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

use*_*256 3 extjs extjs4.2

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

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

该视图包含一个网格:

xtype: 'grid',
columns:[{
.
.
.
.
xtype: 'actioncolumn',
                text: 'Delete',
                width: 100,
                items: [{
                    icon: 'images/deleteEmployee.jpg',
                    tooltip: 'Delete'
                }]
}]
Run Code Online (Sandbox Code Playgroud)

如何在控制器中处理actioncolumn的click事件?

这是控制器的代码:

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

    }
});
Run Code Online (Sandbox Code Playgroud)

Gui*_*pes 8

如果您想使用控制器处理点击,则必须向actioncolumn添加一个处理程序,如下所示:

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');
    }
}]
Run Code Online (Sandbox Code Playgroud)

然后在控制器中为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'));
}
Run Code Online (Sandbox Code Playgroud)

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