ExtJS 网格:在控制器中处理操作列的点击事件

ExtJS grid: handling action column's click event in the controller

我有一个观点'EmployeeList'。它里面有一个网格。我需要从控制器处理 actioncolumn 的点击事件。这是视图:

Ext.define('ExtApp.view.Employees', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.employees',
.
.
.
.
.
});

此视图包含一个网格:

xtype: 'grid',
columns:[{
.
.
.
.
xtype: 'actioncolumn',
                text: 'Delete',
                width: 100,
                items: [{
                    icon: 'images/deleteEmployee.jpg',
                    tooltip: 'Delete'
                }]
}]

如何在我的控制器中处理 actioncolumn 的点击事件?

控制器代码如下:

Ext.define('ExtApp.controller.Employees', {
    extend: 'Ext.app.Controller',
    refs: [{
        ref: 'employees',
        selector: 'employees'
    }],
    init: function () {
        //reference for the grid's actioncolumn needed here

    }
});

如果你想用你的控制器处理点击,你必须像这样向你的操作列添加一个处理程序:

xtype:'actioncolumn',
width:50,
items: [{
    icon: 'extjs/examples/shared/icons/fam/cog_edit.png',  // Use a URL in the icon config
    tooltip: 'Edit',
    handler: function(view, rowIndex, colIndex, item, e, record, row) {
        this.fireEvent('itemClick', view, rowIndex, colIndex, item, e, record, row, 'edit');
    }
}]

然后在您的控制器中为 itemClick 事件添加事件处理程序

init: function() {
    this.control({
         'actioncolumn': {
             itemClick: this.onActionColumnItemClick
         }
     });
},
onActionColumnItemClick : function(view, rowIndex, colIndex, item, e, record, row, action) {
    alert(action + " user " + record.get('firstname'));
}

你应该会看到它在工作,fiddle 这里:https://fiddle.sencha.com/#fiddle/grb