【问题标题】:ExtJS grid: handling action column's click event in the controllerExtJS 网格:在控制器中处理动作列的点击事件
【发布时间】:2015-01-21 12:11:17
【问题描述】:

我有一个视图'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

    }
});

【问题讨论】:

    标签: extjs extjs4.2


    【解决方案1】:

    如果你想用你的控制器处理点击,你必须像这样向你的 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');
        }
    }]
    

    然后在控制器中为 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      • 2013-04-29
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-09-18
      • 2013-05-02
      相关资源
      最近更新 更多