Hi,
I had a situation where I needed to remove records from a store that got it's data via a REST proxy, but I didn't want to actually delete the records from the server, I just wanted them out of the store driving my grid.
The way I was signally which records to remove from the grid / store was by dragging them onto a particular tree node and catching the drop in beforeDrop, removing the dropped records from the grid then cancelling the drop.
I was using store suspendAutoSync() which didn't sync the remove to the server (good) but found that when I did a subsequent drop, the previously dropped and removed records were being deleted from the server via a mysterious destroy operation! (bad).
I discovered that the reason was that the removed records were being saved in the store's removed[] collection in the remove() method. What this meant was that any subsequent proxy operation had a "pending" destroy operation waiting for an opportunity to run.
I also noticed that if I passed a second parameter to the remove() method (private, so it is not in the docs), that would prevent the record from being added to the removed[] collection and hence there would be no pending destroy.
This is my code:
PHP Code:
data.records = [array of records to remove from the store]
var subjStore = this.getVSubjectGrid().store;
subjStore.suspendAutoSync();
Ext.Array.each(data.records, function (rec, index) {
subjStore.remove(rec, true); //<--- passed true here to solve the problem
});
subjStore.resumeAutoSync();
The second parameter to the remove() method is 'isMove' and the relevant part of the remove() method is:
PHP Code:
// don't push phantom records onto removed
if (!isMove && isNotPhantom) {
// Store the index the record was removed from so that rejectChanges can re-insert at the correct place.
// The record's index property won't do, as that is the index in the overall dataset when Store is buffered.
record.removedFrom = index;
me.removed.push(record);
}
By setting isMove to true, the record is not added to me.removed[].
I hope someone else might find this useful.
Cheers,
Murray