2

When calling model.erase({failure..., success...}) the model is removed even when the server responds with a HTTP StatusCode 500. The failure listener is triggered correctly but i would expect that model is not destroyed then. I can see that it is destroyed because it gets removed from the store.

var rec = store.getAt(index);
rec.erase({
     success:function(record, operation){
        // Do something to notify user knows
     }
     failure:function(record, operation){
        // correctly triggered when HTTP = 40x or 50x
        // Would expect that record is still in store. Why not?
        // Of course i could add it again to store with store.add(record) but is that the prefered way?
     }
});

I am using an AJAX proxy in Extjs 6.0

Sebastian
  • 5,721
  • 3
  • 43
  • 69
Robert
  • 176
  • 1
  • 19

2 Answers2

5

Yes, the erase method removes the record from the store right away, without waiting for the server's response. The "hacky" way to handles you scenario will be:

  • set the record's dropped property to true;
  • save the record using the save method (it will generate a delete request but will keep the record in the store);
  • remove the record from the store on success, reset the dropped property to false of failure.

    var record = store.getAt(index);
    record.dropped = true;
    record.save({
        success: function() {
            store.remove(record);
            // do something to notify the user
        }
        failure: function() {
            record.dropped = false;
        }
    });
    
scebotari66
  • 3,395
  • 2
  • 27
  • 34
4

The erase isn't really relevant here. Calling erase calls the model drop method, which marks it as pending deletion and removes it from any stores. Just because the server failed to delete it from the server doesn't necessarily mean you want it back in the store, it's still just pending deletion.

Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
  • So what would be best way to catch this case? – Robert Jun 21 '17 at 14:58
  • 2
    Call `reject` on the model to reset the dropped state, then re-add it to the store if that's what you want to happen. – Evan Trimboli Jun 21 '17 at 15:03
  • Ok, i see. Already guessed that but then it is added at different position. Is there no better way the extjs way? – Robert Jun 21 '17 at 15:08
  • Was testing both approaches and it seems the most straight forward is the one from @Evan Trimboli. In the failure callback you just do record.reject and store.add(record) and everything seems to be fine – Robert Jul 25 '17 at 17:21