3

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

我正在使用 extjs 3.4

Ext.onReady(function () {
  var myData = [[ 'Lisa', "lisa@simpsons.com", "555-111-1224"],
                [ 'Bart', "bart@simpsons.com", "555-222-1234"],
                [ 'Homer', "home@simpsons.com", "555-222-1244"],
                [ 'Marge', "marge@simpsons.com", "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
    })
  });
});
4

3 回答 3

0

您不能像那样将按钮用作列。我们正在使用以下 UX 来实现您所要求的。不幸的是,这是针对 ExtJS 4.1 的:

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

于 2013-03-13T15:49:49.100 回答
0

您会尝试将此作为您的操作列吗

{
    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

于 2013-09-30T13:37:26.710 回答
0

您可以尝试 Grid RowActions

于 2013-04-27T22:12:15.003 回答