Removing a filter from a store in ExtJS
I explicitly add a filter to a Ext.data.Store
using the store.filter(string, string)
method.
H开发者_开发百科owever, I can not figure out how to remove filters from the store. So the filters always apply even after reloading using store.load()
. The only workaround I see is to restart the entire web app.
How do I remove a filter from an Ext.data.Store
?
In addition to Mchi's answer, I want to say that it is possible to remove specific filter (clearFilter() removes them all).
To do that, instead of using store.filter('property_to_filter','value')
method, use:
store.filters.add('filtersId', new Ext.util.Filter({
property: 'property_to_filter',
value: 'value'
}));
store.load();
to remove filter use:
store.filters.removeAtKey('filtersId');
Update (for > 4.2.0)
In 4.2.0 methods for adding/removing specific filter were added:
store.addFilter({
id: 'filtersId',
property: 'property_to_filter',
value: 'value'
});
store.removeFilter('filtersId');
For more info check out docs: Ext.data.Store.addFilter, Ext.data.Store.removeFilter
You need to clearFilter()
Edit: I just found out (browsing the API for something else) that it's even easier. There's a parameter (boolean) which, if true, doesn't reload the data when using remoteFilter...
So here goes :
store.clearFilter(true);
store.filter(...);
Source: Store API > clearFilter
I can't believe I struggled for so long with that. In every forum I looked, I saw clearFilter which wasn't useful for remote filtering, and all I had to do was to add "true"...
Original Post:
"You need to
clearFilter()
"
IMO, this is absolutely not satisfying.
When using a server backend to get the data (as many would), with remoteSort
and remoteFilter
+ paging to manage large result sets, it's even useless.
Calling clearFilter()
actually reloads the data before reapplying the filter. So 2 ajax requests are sent each time a filter is applied. This has bothered ma for a long time.
All you have to do is actually :
store.filters.clear(); // Which is what clearFilter() does just before reloading the data...
store.filter(...);
精彩评论