Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Ext JS store without affecting/deleting records in the server

Tags:

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?

like image 706
Bdfy Avatar asked Feb 19 '11 22:02

Bdfy


3 Answers

Store.loadData([],false);

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

like image 194
Anton Avatar answered Oct 22 '22 14:10

Anton


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();
like image 36
geographika Avatar answered Oct 22 '22 13:10

geographika


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();
like image 30
PavelHolec Avatar answered Oct 22 '22 13:10

PavelHolec