I have a GridPanel and within the toolbar I have two buttons “Reject Changes” and “Save Changes”. The code below shows what each button does, and so far things work as expected.
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);
}
...
});
How to enable/disable the buttons (or any other action) only if the grid data has been modified by the user? I.e. only if any grid row/field becomes dirty (and vice-versa)? Which listener(s) should my code be listening to?
As shown in the question there’s a
CellEditingplugged-in to the Grid. By listening to the CellEditing Plugin’svalidateeditevent, which is fired when data in the grid is changed, one can use the event’s parameters to update the store’s row using the Model instance’ssetfunction. Of course after the required validation is done. The code decides whether to enable/disable the buttons based on whatgetModifiedrecordsreturns.Code: