PDA

View Full Version : Deleting from Grid Store or Ajax Request + reload store?



taelo
20 Dec 2010, 7:31 AM
I am confused as to whether or not I should delete from the store and perform an Ajax request to the database, or to just do the Ajax request, then reload the store. In the code below I am building an array which I can pass to the Ajax request, and I am also removing from the store directly. I know I probably shouldn't be doing it this way, but I can't find any resources to point me in the right direction.


handler: function(){
editor.stopEditing();
var s = portGrid.getSelectionModel().getSelections();
var arr = [];
for(var i = 0, r; r = s[i]; i++){
// Build an array to pass to the Ajax request
arr[i] = r.data.port_id;

// Delete from the store
portGridStore.remove(r);
}

Tim Toady
20 Dec 2010, 8:49 AM
If you have a writer on the store it can handle the ajax for all the CRUD events. With a writer your delete code would simply need to be.



var s = portGrid.getSelectionModel().getSelections();
portGridStore.remove(s);
portGridStore.save();

assuming autoSave is off (not default).

It would then pass a POST parameter (your root) with an array of the field specified as the idProperty.

See http://dev.sencha.com/deploy/dev/examples/writer/writer.html
and
http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DataWriter

taelo
21 Dec 2010, 6:43 AM
Tim, thanks for the insight. It looks as though I created my own CRUD API. I am still new to Ext so I didn't know this ability was built in.