I have been working with applying filters to a store.
Until recently, I have been adding multiple filters to a store using the 'filter' method. I like this approach because I can apply multiple filters to a store and keep track of / remove filters using the filter ID:
E.g.:
Example store:
storeId: 'members',
fields: [
{ name: 'M_NAME' },
{ name: 'COUNTRY' },
{ name: 'GROUP' }
]
I can sring a couple of Filters together to filter by country and group for example:
stores.members.addFilter({
id: 'F_COUNTRY',
property: 'COUNTRY',
exactMatch: true,
value: 'UK'
});
stores.members.addFilter({
id: 'F_GROUP',
property: 'GROUP',
exactMatch: true,
value: 'Developer'
});
So far so good. I can see I have two filters using:
stores.members.filters.length
Remove individual filters using:
stores.members.removeFilter('filter_name')
Or overload a filter :
stores.members.addFilter({
id: 'F_COUNTRY',
property: 'COUNTRY',
exactMatch: true,
value: 'France'
});
I can see the filter has been overloaded as stores.members.filters.length will still return the same number of filters and stores.members.filters.getAt(filter_number).id will still return 'F_COUNTRY' whilst members.filters.getAt(filter_number).value has changed from 'UK' to 'France'.
More recently, I have found the need to add more complex filters that are best achieved using the filterBy method. E.g:
stores. members.filterBy(function(record){
return (record.get('GROUP'=='Developer') || record.get('GROUP'=='Manager'));
});
Now, what I seem to find is that as soon as I apply this filter, is that all previous filters set using the 'filter' method will be ignored. They are still visible using stores.members.filters.getAt(filter_number).id / value and stores.members.filters.length, but are not used.
As soon as I add, remove or overload a filter using the 'filter' and 'removeFilter' methods, the filters created using the 'filter' method become active again and the filter created using the 'filterBy' method becomes inactive.
Also, if I add a new filter using the 'filterBy' method, this seems to override the previous filter.
Given that I can’t find clear documentation on using filter and filterBy together, I pose the following questions:
- Are my previous observations accurate?
- If so, should I, as a result, simply avoid using filter and filterBy together on the same store as they do not seem to be designed to work together?
- If, on the other hand filter and filterBy are intended to be used together, are their some best practice rules? Perhaps a way to give a filterBy an ID?
Thanks in advance for all feedback,
Kind regards, Chopo
Ps. I am currently working with ExtJs V4.2