-
2 Dec 2011 6:20 AM #1Sencha Premium Member
- Join Date
- Jan 2009
- Location
- Melbourne, Australia
- Posts
- 76
- Vote Rating
- 0
- Answers
- 1
Answered: How to change filter on Ext.data.Store without causing re-load
Answered: How to change filter on Ext.data.Store without causing re-load
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
If I call this:Code:Ext.define('MyApp.store.RequestListStoreForSearch', { extend: 'Ext.data.Store', constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callParent([Ext.apply({ 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)]); } });
The store gets loaded for each call, with a race as to which one gets the remote data first/last.Code:store.clearFilter(); store.filter(filters); store.load();
So how do I set and change filters dynamically please?
-
Best Answer Posted by bt_bruno
This is the definition of clearFilter methods:
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 doingCode:clearFilter: function(suppressEvent) { var me = this; me.filters.clear(); if (me.remoteFilter) { me.load(); } else if (me.isFiltered()) { me.data = me.snapshot.clone(); delete me.snapshot; if (suppressEvent !== true) { me.fireEvent('datachanged', me); } } },
Or, like you said, you can temporarily disabled remoteFilterCode:store.filters.clear(); //clear filters without loading store
Doesn't look really nice, but it works at the moment.Code:store.remoteFilter = false; store.clearFilter(); store.remoteFilter = true;
-
2 Dec 2011 8:33 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3102
If you have remoteFilter set to true it will always send a new call to the server when you filter the store.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Dec 2011 9:42 AM #3Sencha Premium Member
- Join Date
- Jan 2009
- Location
- Melbourne, Australia
- Posts
- 76
- Vote Rating
- 0
- Answers
- 1
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 #4Sencha - Services Team
- Join Date
- Mar 2008
- Location
- Redwood City, CA
- Posts
- 145
- Vote Rating
- 7
- Answers
- 10
This is the definition of clearFilter methods:
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 doingCode:clearFilter: function(suppressEvent) { var me = this; me.filters.clear(); if (me.remoteFilter) { me.load(); } else if (me.isFiltered()) { me.data = me.snapshot.clone(); delete me.snapshot; if (suppressEvent !== true) { me.fireEvent('datachanged', me); } } },
Or, like you said, you can temporarily disabled remoteFilterCode:store.filters.clear(); //clear filters without loading store
Doesn't look really nice, but it works at the moment.Code:store.remoteFilter = false; store.clearFilter(); store.remoteFilter = true;
Bruno Tavares, Solutions Engineer
Sencha, Inc.
-
4 Dec 2011 1:55 PM #5Sencha Premium Member
- Join Date
- Jan 2009
- Location
- Melbourne, Australia
- Posts
- 76
- Vote Rating
- 0
- Answers
- 1
Thanks Bruno
store.filters.clear() works a treat


Reply With Quote