3

I have a store in which the user could delete multiple records with a single destroy operation.

Now, a few of these records are locked in the database (because someone else is working on them), and thus cannot be deleted. How can the server tell the frontend that the deletion of records with Id a, b, c was successful, but that records with Id x, y, z could not be deleted and should be moved back into the store and displayed in the grid?

The ExtJS store should know after the sync() which records were really deleted server-side, and which weren't.

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • Is your store ajax driven ? Means each time ajax request is called to update itself ? – Tejas Apr 27 '17 at 10:17
  • @Alexander in the sync you can pass the failure callback with params ```store.sync({ callback: function (records, operation, success) { }, success: function (batch, options) { }, failure: function (batch, options) { } });``` I am not sure but maybe there is something. – pagep Apr 27 '17 at 10:53

1 Answers1

0

I think there's no straightforward solution to this problem. I have opted for the following workaround:

The records now have an "IsDeleted" flag that is set to false by default:

fields:[{
    ...
},{
    name: 'IsDeleted'
    type: 'bool',
    defaultValue: false

The store has a filter that hides entries where the flag is set to true:

filters:[{
    property:'IsDeleted',
    value:false
}]

When the user opts to delete, I don't remove entries from the store, instead I set the IsDeleted flag to true on these entries. The filter makes the user think that the entry has been deleted.

When the store syncs, it does an update operation, not a destroy operation. So the update endpoint of the API then has to delete all entries where IsDeleted is transmitted as true. If it can't delete an entry from the database, the corresponding json as returned to the client gets IsDeleted set to false, so that the frontend gets to know that the deletion of that entry failed.

Alexander
  • 19,906
  • 19
  • 75
  • 162