Check if the store (or records) has been edited?

I have a grid panel, which, when I leave the page, I need a check to see if there are any items in the store (or iterating over models / records) to check if there are unsaved changes / additions.

At first I tried to use panel.getStore().getNewRecords()for new records, but it returns every record currently unloaded. panel.getStore().getUpdatedRecords()seems to ignore entries, even though the lines in the grid have a small red triangle in each cell.

So can anyone advise the correct way to check if there are any new or updated records in the store?

+5
source share
8 answers

.

var records = store.getRange();

for (var i = 0; i < records.length; i++) {
    var rec = records[i];

    if (rec.dirty == true) {
        //Save data
    }
}
+16

, isDirty() Ext.data.Store. , AbstractStore.sync() .

Ext.define(null, {
    override: "Ext.data.Store",
    isDirty: function() {
        return (this.getNewRecords().length > 0 || this.getUpdatedRecords().length > 0 || this.getRemovedRecords().length > 0);
    }
});

ExtJS 4.2.1. , getNewRecords(), , idProperty .

+10

- :

if (panel.getStore(). getModifiedRecords(). length > 0) {   console.log( " " ); }

+4

:

isStoreModified: function(store)
{
  var modifiedRecords = store.getModifiedRecords();
  return modifiedRecords && modifiedRecords.length  && modifiedRecords.length > 0;
},
+1
if (panel.getStore().needsSync) {
    //store have unsaved changes.
}
+1

@theboulderer. , , , , .

MVC, .

, , , .

:

if (this.isDirtyStore(myStore)){
    ...
}

:

isDirtyStore: function(theStore){
    var isDirty = false;

    theStore.each(function(item){
        if(item.dirty == true){
            isDirty = true;
        }
    });
    if (!isDirty){
        isDirty = (theStore.removed.length > 0);
    }
    return isDirty;
}
0

shw ExtJS?, .

, idProperty, .

.

0

, @jstrickers mvc:

:

    Ext.define('YourFolder.overridefolder.DataStore', { 

    override: "Ext.data.Store",
    isDirty: function() {
        return (this.getNewRecords().length > 0 || this.getUpdatedRecords().length > 0 || this.getRemovedRecords().length > 0);
    }

});

Add this file to the appropriate folder and specify it in app.js 'required', then isDirty will be available in your ext.data.store file

Works great and the feature will be available if you need it.

0
source

All Articles