ExtJS Grid事件处理

时间:2011-10-23 07:16:51

标签: javascript events extjs grid extjs4

考虑这个例子: http://docs.sencha.com/ext-js/4-0/#!/example/grid/binding-with-classes.html 我想在控制器中处理'selectionchange'事件。如下面的代码:

Ext.define('AM.controller.Users', {
    init: function() {
        this.control({
            'useredit button[action=save]': {
                click: this.updateUser
            }
        });
    },

    updateUser: function(button) {
        console.log('clicked the Save button');
    }
});

我该怎么做? 感谢

1 个答案:

答案 0 :(得分:1)

你的网格:

Ext.define('MyApp.view.ui.MyGridPanel', {
    extend: 'Ext.grid.Panel',
    alias:'widget.mygridpanel',

    height: 250,
    width: 400,
    title: 'My Grid Panel',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            columns: [
                {
                    xtype: 'gridcolumn',
                    dataIndex: 'string',
                    text: 'String'
                },
                {
                    xtype: 'numbercolumn',
                    dataIndex: 'number',
                    text: 'Number'
                },
                {
                    xtype: 'datecolumn',
                    dataIndex: 'date',
                    text: 'Date'
                },
                {
                    xtype: 'booleancolumn',
                    dataIndex: 'bool',
                    text: 'Boolean'
                }
            ],
            viewConfig: {

            }
        });

        me.callParent(arguments);
    }
});

您的控制器是:

Ext.define('AM.controller.Users', {
    init: function() {
        this.control({
            'useredit button[action=save]': {
                click: this.updateUser
            },
            'mygridpanel':{
                selectionchange:this.changeselection
            }
        });
    },

    changeselection:function(selectionModel,record){
        console.log(record);
    },

    updateUser: function(button) {
        console.log('clicked the Save button');
    }
});