8
votes

I am using ExtJS 4.1. I am using stores's clearFilter() to remove the filter from the store. I am applying filter to the store by using filterBy method. I am filtering all the records where name is not Ronaldo.

After clearing the filter, I load a view which contains a grid (attached to store). But when I load the grid, I can still see that filter is not cleared. The store is local store. I have not applied any grouping on the store. Store is only using one model.

myStore.filterBy(function (record) {
    if (record.get('Name') != 'Ronaldo') {
        return true;
    }
});

While all this is working fine, but when I clear the filter by using clearFilter(), it is taking some time. Is there any faster\better\correct way to clear the filter on a store when filter is applied by using filterBy()?

3
When you say "it" is taking some time, what is "it"? The store? The grid/dataview? Are you filtering remotely or locally? Do you have groups applied? Are you suppressing the event on the clearFilter()? And how many model instances are in your store? All or some or none of these could be important to your issue, but without knowing more details it's difficult to suggest anything, given that the clearFilter() should be a very fast process (check the source: docs.sencha.com/extjs/4.2.1/source/…)existdissolve

3 Answers

12
votes

When you use clearFilter() it doesn't make a difference if you used filterBy() or filter() or the filters were configured on the store.

Here's what happens when you clear the filters:

  1. the collection of filters on the store is cleared
  2. the filtered data is replaced with the original (unfiltered) data which was stored in a snapshot
  3. the "datachanged" and "refresh" events are fired on the store

Note that you can suppress the events to be fired by using clearFilter(true) which may be useful if you want to filter the store again after clearing the existing filters.

If clearing the store's filters performs slowly then it is probably related to the layout process (on your grid or whatever you're using the store with) which is triggered by step 3.

Also refer to the docs or the source code.

3
votes

heres my best answer, to clear the filterBy function :

 myStore.filterBy(function (record) {
                return true;
        });

i just did it, hope its helping

0
votes

Just call a:

myStore.reload();

whenever you want to remove a filter set using filterBy.