ExtJS 网格:在控制器中处理操作列的点击事件 [英] ExtJS grid: handling action column's click event in the controller

查看:16
本文介绍了ExtJS 网格:在控制器中处理操作列的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图EmployeeList".里面有一个网格.我需要处理来自控制器的 actioncolumn 的点击事件.这是视图:

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

此视图包含一个网格:

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

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

How do I handle the actioncolumn's click event in my 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

    }
});

推荐答案

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

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

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

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

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

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

这篇关于ExtJS 网格:在控制器中处理操作列的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆