Reputation: 3956
I am currently working on a Sencha Touch application that has a large store of all data, and I want to work with only a subset of that data. The store has been filtered down to the subset, and then I may want to filter it further.
I can add filters to the store easily enough by using filter(col, val). But how do I remove/clear only that filter, if I want to 'revert' my dataset to the 'original' less-filtered-but-still-filtered data?
In the API documentation, I can only find clearFilter() which is useless, as it removes all of the previously set filters.
I can only think that the way to do it would be to take a snapshot of the original filters, clear all filters, and then re-apply the original filters... but that sounds like it would impact performance quite significantly, especially if the original dataset was large.
Is there a better way to do this?
Upvotes: 1
Views: 2045
Reputation: 25001
That will not work with locally filtered stores, and that uses some undocumented features, so that may exposes you to future API changes, but you can access the data
property of you store, of type Ext.util.Collection
that does expose a removeFilters
method.
Looking at its implementation, you see that you can remove your filters with a call of this type:
store.data.removeFilters(col);
// remove all filters at once, because the collection will be updated for each call to removeFilters
store.data.removeFilters([col1, col2]);
After doing that, you'll have to manually trigger the events to notify things bounded to the store:
var data = store.data;
store.fireEvent('filter', store, data, data.getFilters());
store.fireEvent('refresh', store, data);
Now, applying a new filter set will imply looping through all the items in the collection (as opposed to only the ones that already passed the previous filters). So unless I've missed something, removing filters instead of, for example, replacing the currently set filters with a complete new set won't get you any performance gain.
What you must careful about is applying the desired filter changes all at once (be it by removing or adding them), because all filter methods will trigger a pass on all items.
If I were you I wouldn't worry too much though, because AFAIK looping through a few thousand objects should be an almost instantaneous operation, even on a small processor like a phone.
Upvotes: 2