I have a Grid Panel, which when I leave the page, I want a check to see if any items in the store (or iterate through models/records) to check if there are any unsaved changes/additions.
I initially tried using panel.getStore().getNewRecords()
for new records, but it returns every record currently paged in. panel.getStore().getUpdatedRecords()
seems to ignore records, despite lines in the grid having the small red triangle in each cell.
So can anyone advise on the correct way to check if any new or updated records exist in a store?
In order to keep the dirty checking logic encapsulated, I chose to add an isDirty()
method to the Ext.data.Store
object. I utilized the same logic that AbstractStore.sync()
uses to determine whether the store needs to sync.
Ext.define(null, {
override: "Ext.data.Store",
isDirty: function() {
return (this.getNewRecords().length > 0 || this.getUpdatedRecords().length > 0 || this.getRemovedRecords().length > 0);
}
});
I'm using ExtJS 4.2.1. If all of your records are returned when you call getNewRecords()
you should check that you've set a value for idProperty
on your model.
This may work for you.
var records = store.getRange();
for (var i = 0; i < records.length; i++) {
var rec = records[i];
if (rec.dirty == true) {
//Save data
}
}
You can use something like the code below:
if(panel.getStore().getModifiedRecords().length > 0) {
console.log('store has dirty records');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With