View Full Version : How to change filter on Ext.data.Store without causing re-load

2 Dec 2011, 6:20 AM
On Ext 4.0.7 with Ext Designer 1.2.2

The filter() method on Ext.data.Store keeps adding new filters with each call. I don't want it to do that so I call clearFilter() first. But this causes the store to load the data, and then it loads it again when I call filter(). This happens even with the autoload config not set. Here is my Store as created by Ext Designer

Ext.define('MyApp.store.RequestListStoreForSearch', {
extend: 'Ext.data.Store',
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
storeId: 'requestListStoreForSearch',
pageSize: 10,
remoteFilter: true,
remoteGroup: true,
remoteSort: true,
proxy: {
type: 'ajax',
simpleSortMode: true,
url: '../spring/request/list',
reader: {
type: 'array',
root: 'data'
fields: [ ...
}, cfg)]);

If I call this:


The store gets loaded for each call, with a race as to which one gets the remote data first/last.

So how do I set and change filters dynamically please?

2 Dec 2011, 8:33 AM
If you have remoteFilter set to true it will always send a new call to the server when you filter the store.

2 Dec 2011, 9:42 AM
Thanks Mitchell

The result set would be too big without filters so I need them to be applied remotely, but I also need to change them dynamically so that the user can perform searching. What is the method for doing this without causing two asynchronous loads to be done, one for clearFilter() and one for filter()

Is there perhaps a way to turn off remoteFilter temporarily while I call clearFilter()? I can't see a method in the docs for that.

2 Dec 2011, 12:00 PM
This is the definition of clearFilter methods:
clearFilter: function(suppressEvent) {
var me = this;


if (me.remoteFilter) {
} else if (me.isFiltered()) {
me.data = me.snapshot.clone();
delete me.snapshot;

if (suppressEvent !== true) {
me.fireEvent('datachanged', me);

If you use it remotely, it only calls me.filters.clear(), and then me.load();. The docs expose filters as a property of datastore, so you should be fine doing

store.filters.clear(); //clear filters without loading store

Or, like you said, you can temporarily disabled remoteFilter

store.remoteFilter = false;
store.remoteFilter = true;

Doesn't look really nice, but it works at the moment.

4 Dec 2011, 1:55 PM
Thanks Bruno
store.filters.clear() works a treat