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

落花浮王杯 提交于 2019-12-01 06:40:27

问题


I have a view 'EmployeeList'. Inside it there is a grid. I need to handle the actioncolumn's click event from controller. Here is the view:

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

This view contains a grid:

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

How do I handle the actioncolumn's click event in my controller?

Here is the controller's code:

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

    }
});

回答1:


If you wanna handle the clicks with your controller, you will have to add a handler to your actioncolumn like this:

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

And then add event handler in your controller for the itemClick event

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

And you should see it working, fiddle here: https://fiddle.sencha.com/#fiddle/grb



来源:https://stackoverflow.com/questions/28066941/extjs-grid-handling-action-columns-click-event-in-the-controller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!