Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJS:检测网格数据更改的网格面板事件是什么_Javascript_Extjs_Extjs4.1 - Fatal编程技术网

Javascript ExtJS:检测网格数据更改的网格面板事件是什么

Javascript ExtJS:检测网格数据更改的网格面板事件是什么,javascript,extjs,extjs4.1,Javascript,Extjs,Extjs4.1,我有一个网格面板,在工具栏中有两个按钮“拒绝更改”和“保存更改”。下面的代码显示了每个按钮的功能,以及到目前为止的工作情况 Ext.define('APP.view.MyGrid' ,{ extend: 'Ext.grid.Panel', ... initComponent: function() { var me=this; me.store = myStore; me.plugins = [

我有一个网格面板,在工具栏中有两个按钮“拒绝更改”和“保存更改”。下面的代码显示了每个按钮的功能,以及到目前为止的工作情况

Ext.define('APP.view.MyGrid' ,{
    extend: 'Ext.grid.Panel',

    ...

    initComponent: function() {    
        var me=this;
        me.store = myStore;         
        me.plugins = [
            Ext.create('Ext.grid.plugin.CellEditing', {
                clicksToEdit: 1, autoCancel: false
            }),
        ];          
        me.rejectBtn = {
            xtype:'button', id:'kbsGridCancelBtn', text:'Reject changes',
            handler: function() { me.store.rejectChanges(); }
        },      
        me.saveBtn = {
            xtype:'button', id:'kbsGridSaveBtn', text:'Save changes',
            handler: function() { me.store.sync(); }
        },      
        me.bbar = Ext.create('Ext.toolbar.Toolbar', {
            items : [{ xtype: 'tbfill'},me.rejectBtn,'-',me.saveBtn] 
        });

        me.callParent(arguments);
    }

    ...

});
仅当用户修改了网格数据时,如何启用/禁用按钮(或任何其他操作)?即,仅当任何网格行/字段变脏时(反之亦然)?我的代码应该侦听哪个侦听器?

Ext.data.Store datachanged(这是eOpts)。 每当存储区中的记录以某种方式发生更改时激发—这可能包括添加或删除记录,或更新现有记录中的数据


当您手动更改存储记录时,请调用
dataChangedFun(myStore)

如问题所示,有一个已插入电网的电源。通过监听CellEditing插件的事件(当网格中的数据更改时触发),可以使用事件的参数使用模型实例的函数更新存储的行。当然,在完成所需的验证之后。代码根据返回的内容决定是否启用/禁用按钮

代码:


谢谢你的回复;我试着听
datachanged
。但是,当我更改网格中的数据,然后通过
set()
手动更改存储的记录(类型为
Ext.data.Model
),然后通过
commit()
,这个事件仍然没有触发:/I我没有盲目复制您的代码示例,因为为了通信起见,我在上面放置的代码结构被简化了。找到了另一个解决方案;在我吃了东西之后,我会用答案更新这个问题;无论如何,谢谢,+1ed:)
function dataChangedFun(store){
    // code here
}

myStore.on("datachanged", dataChangedFun, this);
...

listeners: {
    'validateedit': function(cep, e, eOpts) {
        var me = this,            
            rowIdx = e.rowIdx, // row index
            fieldName = e.field,
            newVal = e.value,
            storeRow = this.store.getAt(rowIdx);

        // assuming valid input, proceed with the below    
        storeRow.set(fieldName, newVal);

        // if modified records > 0 then enable buttons
        var enableButtons = Boolean(me.store.getModifiedRecords().length);

        if (enableButtons) {
            /* enable buttons */
        } else { /* disable buttons */ }        

    }, scope: this
}

...