View Full Version : How to revert destroy when server return a failure

25 Jan 2012, 6:57 AM

When the server response to a delete operation (from a model instance destroy call) is a failure (success to false), the store doesn't revert the operation and the instance is nevertheless deleted from the application.
I looked into extjs source files and it seems that the model instance is first removed from the store and after, the proxy is called. The proxy result is just used for user callback function. Is that correct or Have i bad understand some thing ?

If my analysis is correct, how to implement a "rollback" operation ?


25 Jan 2012, 8:59 AM
You may use the following override:

Ext.override(Ext.data.Store, {
rejectChanges: function() {
var me = this;

// re-add removed records
Ext.each(me.removed, function(rec) {
me.removed = [];

// revert dirty records and trash newly added records ('phantoms')
me.each(function(rec) {
if (rec.dirty) {
if (rec.phantom) {

On failure, you can call:


If you just want to do it for delete, then you can remove if conditions. The deleted records are stored in the "removed" array in the store.


26 Jan 2012, 12:47 AM
Thanks Farish,

Your solution can "rollback" a delete operation (or update) but it add records at the end of the store and not the previous position.
And I think that if the store is a TreeStore, it doesn't work.

26 Jan 2012, 1:55 AM
i havent tried this with a tree store. If you want to reinsert the deleted records at their original position, I dont know any short way for that. What you could do is to push the index and id of the record to be removed into another array before calling store.remove. The when you want to rollback, use insert instead of add and use the position from that array for insert. OR if your records are sorted, you can add them at the end and just call store.sort(fieldname, direction).