PDA

View Full Version : Load remote store and mark records as new



Qarea
15 Feb 2018, 2:31 PM
I have remote store and after it loads need to mark all records as new, to make store.getNewRecords() return all this loaded records. Between store loading and getNewRecords call user is editing grid with cellediting plugin and he also can add/delete records, thats why I cant simply call store.getRange().

Initially I expected that smth like that will work:

grid.getStore().load({
params: {file: file.getId()},
callback: function (records, operation, success) {
records.forEach(function(record) {
record.phantom = true;
record.set('id', '');
});
}
});
but that produces different weird issues, like only one record is returned in store.getNewRecords() and etc. The only working without issues code is:


copyStore = Ext.create('Ext.data.Store', {
model: 'myModel'
})
grid.setLoading(true)
grid.getStore().removeAll();
copyStore.load({
params: {file: file.getId()},
callback: function (records, operation, success) {
records.forEach(function(record) {
grid.getStore().add(record.copy());
});
grid.setLoading(false);
}
});


Maybe there is better solution? I'm using ExtJS4 in this old project, but probably things are same for extjs4-5-6