PDA

View Full Version : store.remove(recs[]) question



Bleak
14 Oct 2010, 4:52 AM
I have a datastore configured with autoSave:true, which is associated to a grid that allows multiple selections.

Everything works, but I've noticed a strange scenario. If I select three records from the grid and choose to delete them the following code runs;



,onDelete: function(menu, evtObj) {
var recs = menu.grid.getSelectionModel().getSelections();
menu.grid.store.remove(recs);
}
I'm simply using the Store.remove(rec[]) method, but since the store is configured as auto save, the store is making 3 calls to the backend. For the sake of this question, assume that the 3 selected records have the ids of 1, 2 and 3.

The call stack look as follows;

destroy - call 1:
[{"id":1}]

destroy - call 2:
[{"id":1},{"id":2}]

destroy - call 3:
[{"id":1},{"id":2},{"id":3}]

If I select 20 records, it'll make more calls such as this (provided the backend doesn't respond with some of the previously submitted requests).

If I set autoSave: false, this isn't a problem of course. But the grid is meant to be interactive and save as the user goes. Does the Store.remove(rec[]) method iterate over the record array and actually remove them 1 at a time firing the remove event?

mrgreenbeans
4 Nov 2010, 6:30 AM
Just putting a +1 to this issue.

Looking at the source, if you hand it an array it recursively calls remove for each record firing the remove event each time.

darthwes
4 Nov 2010, 6:34 AM
Then turn autoSave off and do

store.remove(recs);
store.save();
?