如何从网格编辑器中选择网格?

时间:2012-02-14 10:08:51

标签: javascript extjs web

ExtJS 4。 我有网格和编辑器。编辑有听众。如何从监听器访问网格?

var grid = Ext.create('Ext.grid.Panel',{
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 2,
    pluginId: 'cellplugin'
})],
columns: [
    {
    header: 'Name',
    dataIndex: 'name',
    editor: {
        xtype: 'textfield',
        listeners: {
            specialkey: function(field, e) {
                if (e.getKey() == e.ENTER) {
                    !!!NEED TO ACCESS GRID HERE, FOR EXAMPLE IN VARIABLE!!!
                    var grid = SOME?CODE?;
                }
            }
        }
    }},
    // ...
],
// ...

});

我可以合并编辑器而不是这个网格。所以这个命令需要是通用的。

1 个答案:

答案 0 :(得分:1)

var grid = Ext.create('Ext.grid.Panel',{
itemId : 'gridPanel',   //we need to call your grid somehow
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 2,
    pluginId: 'cellplugin'
})],
columns: [
    {
    header: 'Name',
    dataIndex: 'name',
    editor: {
        xtype: 'textfield',
        listeners: {
            specialkey: function(field, e) {
                if (e.getKey() == e.ENTER) {
                    var grid = this.up('#gridPanel'); //and access it like this
                }
            }
        }
    }},
    // ...
],
// ...