2013-03-13 131 views
3

我创建了一个Ext.grid.GridPanel。我正在尝试将列号xtype: button添加到列模型中。我不确定,如果我能做到这一点。下面是我的代码,也这是的jsfiddle http://jsfiddle.net/bXUtQ/将Ext.Button添加到ExtJS columnmodel

我使用ExtJS的3.4

Ext.onReady(function() { 
    var myData = [[ 'Lisa', "[email protected]", "555-111-1224"], 
       [ 'Bart', "[email protected]", "555-222-1234"], 
       [ 'Homer', "[email protected]", "555-222-1244"], 
       [ 'Marge', "[email protected]", "555-222-1254"]]; 

    var store = new Ext.data.ArrayStore({ 
    fields:[ { 
     name: 'name' 
    }, 
    { 
     name: 'email' 
    }, 
    { 
     name: 'phone' 
    }], 
    data: myData 
    }); 
    var grid = new Ext.grid.GridPanel({ 
    renderTo: 'grid-container', 
    columns:[ { 
     header: 'Name', 
     dataIndex: 'name' 
    }, 
    { 
     header: 'Email', 
     dataIndex: 'email' 
    }, 
    { 
     header: 'Phone', 
     dataIndex: 'phone' 
    }, 
    { 
     header: 'action', 
     xtype: 'actioncolumn', 
     iconCls: 'delete-icon' 
     text: 'Delete', 
     name: 'deleteBtn', 
     handler: function(grid, rowIndex, colIndex, item, e) { 
      alert('deleted'); 
     }  
    },    

    ////////////////////////////// 
    //I cannot add this column 
    { 
     header: 'action', 
     xtype: 'button', 
     text: 'update', 
     name: 'btnSubmit' 
    } 
    ], 
    store: store, 
    frame: true, 
    height: 240, 
    width: 500, 
    title: 'Framed with Row Selection', 
    iconCls: 'icon-grid', 
    sm: new Ext.grid.RowSelectionModel({ 
     singleSelect: true 
    }) 
    }); 
}); 
+0

您使用的是'actioncolumn'为您删除“按钮”。为什么不把它用于你的提交按钮呢? – A1rPun 2013-03-13 15:58:31

+0

actioncolumn用于测试xtype。谢谢。 – user2073131 2013-03-13 16:08:05

回答

0

不能使用一个按钮,就这样一列中的链接。我们正在使用以下UX来实现你所要求的。不幸的是这是ExtJS的4.1:

http://www.sencha.com/forum/showthread.php?148064-Component-Column-Components-in-Grid-Cells

+0

我发现这个http://techmix.net/blog/2010/11/25/add-button-to-extjs-gridpanel-cell-using-renderer/ 所以我修改了一下我的代码,你可以看看在这里http://jsfiddle.net/bXUtQ/1/。它似乎臃肿。但现在按钮在那里。 – user2073131 2013-03-13 16:11:58

+0

所以你有解决方案?如果可以,请将修改后的代码放在这里,并将其作为答案。因此,在接受的答案中进行深入研究将会很有帮助。 – vajrakumar 2013-04-16 15:35:21

0

你会尝试这是您的actioncolumn

{ 
    xtype: 'actioncolumn', 
    width: 50, 
    items: 
    [ 
     { 
      icon: 'app/resources/images/cog_edit.png', // Use a URL in the icon config 
      tooltip: 'Edit', 
      handler: function (grid, rowIndex, colIndex) { 
       var rec = grid.getStore().getAt(rowIndex); 
       alert("Edit " + rec.get('name')); 
      } 
     }, 
     { 
      icon: 'app/resources/images/delete.png', 
      tooltip: 'Delete', 
      handler: function (grid, rowIndex, colIndex) { 
       var rec = grid.getStore().getAt(rowIndex); 
       alert("Terminate " + rec.get('name')); 
      } 
     } 
    ] 
} 

或者你可以尝试这个插件为actioncolumnbutton