Note that there are some explanatory texts on larger screens.

plurals
  1. POCancel store.remove after server call in ExtJS 4
    primarykey
    data
    text
    <p>I'm using ExtJS 4 and have an Ext.data.Store with an ajax proxy and api:</p> <pre><code>var gridStore = Ext.create('Ext.data.Store', { autoSync: true, proxy: { type: 'ajax', api: { read: 'myurl', create: 'myurl', update: 'myurl', destroy: 'myurl' }, reader: { type: 'json', successProperty: 'success', root: 'data', messageProperty: 'message' }, writer: { type: 'json', writeAllFields: false, root: 'data' }, listeners: { exception: function(proxy, response, operation){ Ext.MessageBox.show({ title: 'Server error', msg: operation.getError(), icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK }); } } ... </code></pre> <p>When I use the update function and my server returns a json object with <code>success:false</code> (because he entered something wrong) the field in my associated grid is still marked as changed and the user has the option to change his wrong value.</p> <p>That works fine.</p> <p>But when I remove a record from the store...</p> <pre><code>var store = Ext.StoreManager.lookup('gridStore'); store.remove(store.getById(id)); </code></pre> <p>...then ExtJS removes this record from the store first and call the ajax api afterwards. So when the destroy api returns <code>success:false</code> the message is shown as exception like in the update api, thats fine, but my record has been removed from the store! As example the exception from the server says that you cannot remove this record because of whatever but it's already removed in the store.</p> <p>How to cancel the store removement after the server sync? I want the record to stay in the store if the server returns <code>success:false</code>.</p> <p>Any idea? Maybe a bug?</p> <hr> <p>UPDATE <strong>SOLUTION</strong></p> <p>Based on Ryan's anwer, I modified the exception listener as following, which works very well:</p> <pre><code> listeners: { exception: function(proxy, response, operation){ Ext.MessageBox.show(...); // get the removed records and insert them where they have been var removedRecords = gridStore.getRemovedRecords(); for(var i=0; i&lt;removedRecords.length; i++){ var record = removedRecords[i]; gridStore.insert(record.index, record); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload