Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 517
SharpCoder Avatar asked Nov 04 '13 12:11

SharpCoder


1 Answers

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.

like image 171
matt Avatar answered Sep 22 '22 04:09

matt