PDA

View Full Version : Filter with an array



gisada
12 Dec 2011, 6:18 AM
I have a simple filter:

var testfilter = new Ext.util.Filter({

property: 'dags',
value : dates,
root : 'data'
});
The problem is that the filter variable "dates" that I want to use is not a single data like ’21.12.2012’ but an array of dates. Does anyone know how to filter on multiple values?

skirtle
12 Dec 2011, 8:14 AM
It's quite rare that you'd need to create an instance of Ext.util.Filter yourself, usually whatever you're filtering has some kind of shorthand for specifying filters.

If you do want to use an Ext.util.Filter with multiple values then I think you'd need to use a filter function:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.util.Filter-cfg-filterFn

gisada
12 Dec 2011, 8:54 AM
Thank you skirtle.

Can you give me an example of a shorthand way to use array as a condition in a filter? Like for example in this case:

gridstore.filter([{property: "dags", value: dates}]);
where dates are:

dates = ["01.08.2011", "02.08.2011"]

skirtle
12 Dec 2011, 9:18 AM
Try this:


gridstore.filterBy(function(record) {
return Ext.Array.contains(dates, record.get('dags'));
});

gisada
12 Dec 2011, 10:29 AM
Thank you skirtle I appreciate your help :D