PDA

View Full Version : Filter store data by 2 values for the same column



sshres
12 Feb 2012, 5:08 AM
Hi All,

I am a newbie to ExtJS and have a question. How can I filter data in store by passing multiple values for the same column. The requirement is user wants to see data for two different status together. For eg. I have a column named 'Status'. I want to filter the data by passing values like this:
property: status, value: "In progress"
property: status, value: "Rejected"
and so on...

Thanks

dedoz
12 Feb 2012, 6:57 AM
your question is bout store.filter ?
store.filter("email", /\.com$/);
check documentation, im not familiar with filtering but second argument seems to accept a regex u can use to make status equal to "in progress" or "Rejected"

also filters accepts functions (check the store.filter documentation too)
{filterFn: function(item) { return item.get("age") > 10; }}

so maybe u can do something like
return (item.get('status') == 'In progress' || item.get('status') == 'Rejected')

or your question its bout loading records from server that correspond to "where status = 'in progess' or status ='rejected'"?

(sorry for my bad english)

sshres
12 Feb 2012, 10:26 PM
Thanks. My questions was on store.filter and your solution worked!

sivamurthy
19 Dec 2013, 9:42 PM
Hi All,
I have to filter the sencha touch store with one property with multiple values, array of values will come dynamically.
Ex: I have to filter the store for property name with values 'india','america','japan' but values will come dynamically.

Please let me know how to filter the with above constraints.

Thanks,
siva.

AkshayKalbhor
29 Sep 2014, 11:18 PM
You can use the below function when the values on which you want to filter are available in the form of an array.

Here I have to filter the records on [1,4,5] which is the id's of selected records from a multiselect dropdown which is available in "filterIds".


filterGrid : function(filterIds) { this$ = this;
if(filterIds.length <= 0) {
this$.removeFilter();
}

if(filterIds.length != 0) {
this$.filterBy(function(record, id){
// record is the individual record from the store.

var recordFlag = false;
Ext.each(filterIds, function(filter) {
if(record.get('quotaTypeId') === filter) {
recordFlag = true;
};
});
return recordFlag;
}, this);
}
}