25

I have a Ext JS grid store with autosave set to false.

I want to clear ONLY the local store, without affecting/deleting records in the server.

If I try store.removeAll(), then when the next store write occurs, all records are deleted.

How to call store.removeAll with clearing all pending changes after it?

Christiaan Westerbeek
  • 10,619
  • 13
  • 64
  • 89
Bdfy
  • 23,141
  • 55
  • 131
  • 179

4 Answers4

52
Store.loadData([],false);

This statement drop local cache and not send changes to server side

Anton
  • 536
  • 5
  • 3
6

The removeAll has a silent parameter that can be used to clear records rather than delete from the server:

http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.data.Store-method-removeAll

gridPanel.store.removeAll(true);

From the code comments:

    if (silent !== true) {  // <-- prevents write-actions when we just want to clear a store.
        this.fireEvent('clear', this, items);
    }

If you then manually want to update a GridPanel to clear all rows you need to call:

gridPanel.view.refresh();
geographika
  • 6,458
  • 4
  • 38
  • 56
2

For ExtJS 4.1, this will clear buffer cache (prefetched data), so the next time you load (or loadPage), store will reload the pages from scratch:

store.pageMap.clear();

which was previously done as:

store.prefetchData.clear();
PavelHolec
  • 21
  • 1
1

Ok, from what I understand you want to ignore changes to the local store and not send it to the server side. Have you tried using:

myStore.rejectChanges();

This method clears all outstanding changes on all modified records. This will reject all pending changes.

Abdel Raoof Olakara
  • 19,223
  • 11
  • 88
  • 133