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

标签 extjs extjs4.2

我有一个 View “EmployeeList”。里面有一个网格。我需要处理来自 Controller 的操作列的单击事件。这是 View :

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

该 View 包含一个网格:

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

如何在 Controller 中处理操作列的单击事件?

这是 Controller 的代码:

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

    }
});

最佳答案

如果您想使用 Controller 处理点击,则必须向操作列添加一个处理程序,如下所示:

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');
    }
}]

然后在 Controller 中为 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'));
}

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

关于ExtJS网格: handling action column's click event in the controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066941/

相关文章:

javascript - 如何在某些条件下更改网格存储

javascript - Extjs GridFilter 功能不起作用

javascript - 如何在 ExtJs 中维护文件字段的状态

extjs - 如何在extjs中设计权限和条件加载

HTML:如何创建可缩放的布局,并将元素粘在边缘

javascript - ExtJS - 使用自定义 TriggerField 作为 GridEditor

javascript - 如何将 Ext JS Controller 与 View 一起使用?

javascript - ExtJS 4.2 更大的选项卡关闭图标?

extjs - Extjs中窗口大小改变时如何显示 'pagingtoolbar'?