首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Ext中向Ext.grid.GridPanel() 增添按钮和点击事件

2013-03-04 
Ext中向Ext.grid.GridPanel() 添加按钮和点击事件如何向EXTJS的Ext.grid.Panel()的列添加按钮,并添加点击

Ext中向Ext.grid.GridPanel() 添加按钮和点击事件
如何向EXTJS的Ext.grid.Panel()的列添加按钮,并添加点击事件,可以取出所点击行的所有列的值?
谢谢啦!
Ext.create('Ext.data.Store', {
    storeId:'employeeStore',
    fields:['firstname', 'lastname', 'senority', 'dep', 'hired'],
    data:[
        {firstname:"Michael", lastname:"Scott"},
        {firstname:"Dwight", lastname:"Schrute"},
        {firstname:"Jim", lastname:"Halpert"},
        {firstname:"Kevin", lastname:"Malone"},
        {firstname:"Angela", lastname:"Martin"}                        
    ]
});

Ext.create('Ext.grid.Panel', {
    title: 'Action Column Demo',
    store: Ext.data.StoreManager.lookup('employeeStore'),
    columns: [
        {text: 'First Name',  dataIndex:'firstname'},
        {text: 'Last Name',  dataIndex:'lastname'},
        {
            xtype:'actioncolumn', 
            width:50,
            items: [{
                icon: 'images/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('firstname'));
                }
            },{
                icon: 'images/delete.png',
                tooltip: 'Delete',
                handler: function(grid, rowIndex, colIndex) {
                    var rec = grid.getStore().getAt(rowIndex);
                    alert("Terminate " + rec.get('firstname'));


                }                
            }]
        }
    ],
    width: 250,
    renderTo: Ext.getBody()
});

[解决办法]
同意楼上的方法,楼上是通用的方法;如何想添加按钮的话是否用renderer方法,返回一个按钮不知道是否可行,没试过;

热点排行