PDA

View Full Version : Handle remove/update action on a store



tR4x0u
10 Jul 2013, 6:28 AM
Hi everybody,

When I perform CRUD operation in my application, I'd like to be able to get the request BEFORE it is sent to my server.

For example, when I remove or update a record from a grid, it works well but the request sent to the server is composed by each properties of my object separately. I'd like to send my entire object instead.
So I need to handle the remove / update operation and encapsulate my object to get only one parameter for my request containing the object.

I tried to do this inside my store (for the remove operation for example):


listeners: {
beforeload: function (store, operation, eOpts) {

console.log(operation.action);

if (operation.action == "destroy") {

console.log("destroy started");
operation.params = {
boardToDelete: operation.params
};

operation.params = Ext.encode(operation.params);

Ext.encode(operation.params);
}
}
}

However I cant test this code because the beforeload event is not fired when I update or remove a record, it is fired only when I perform a read operation. I can't get a store event which could fire at the good time and allowing me to access the operation.

I hope you understood what I need, thanks in advance.

Farish
10 Jul 2013, 6:55 AM
you can use the store's datachanged event instead. but this might be fired on load also. you can put an if condition inside it to check if there are any deleted or updated records):


store.on('datachanged', function() {
if(store.getRemovedRecords().length != 0 || store.getUpdatedRecords().length != 0)
{
// your code here
}
});

tR4x0u
10 Jul 2013, 7:41 AM
Thanks but how can I access into this event the operation object to add it my parameter ?

Farish
11 Jul 2013, 2:43 AM
hmm. i think thats not available for datachanged. how about using the beforesync (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store-event-beforesync) event? there you have the records to be synced available according to the documentation. would this be helpful for you?