Fastest way to clear filter from ExtJs store when filter is applied by using filterBy()
Asked Answered
P

3

9

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()?

Putman answered 4/11, 2013 at 12:33 Comment(1)
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/…)Narcotic
N
14

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.

Nickeliferous answered 4/11, 2013 at 13:32 Comment(1)
Fetching new (unfiltered) data takes some time too, if you have remoteFilter = true.Bacon
D
4

heres my best answer, to clear the filterBy function :

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

i just did it, hope its helping

Destefano answered 30/8, 2014 at 4:14 Comment(1)
This might be the easiest solution to the problem. I have a remotely filtered store used in combobox, but I want to filter it locally when user types something in the input, so I am using store.filterBy() method also. If I used clearFilter() method, my remote filters would be lost.Mira
W
0

Just call a:

myStore.reload();

whenever you want to remove a filter set using filterBy.

Wares answered 20/2, 2014 at 12:40 Comment(1)
But that would reload the store, which is really unnecessary when you just want to remove local filters.Mira

© 2022 - 2024 — McMap. All rights reserved.