PDA

View Full Version : How to filter store when field value is an object?



dbassett74
11 Sep 2009, 6:02 AM
I have successfully implemented a filter on a grid, using the following:



gridActive.getStore().filter("id", new RegExp("^1049$"));
However, there are other fields in the store that are not simple values, but rather, objects. So field "project", is actually:



project = {
id: 1,
name: "blablabla"
}
So what do I specify for the "value" parameter of the filter if I want to search on project.name?

Condor
11 Sep 2009, 6:05 AM
store.filterBy(function(r){
return r.get('project').name == 'blablabla';
});

dbassett74
11 Sep 2009, 6:10 AM
Thanks!

dbassett74
11 Sep 2009, 6:26 AM
How do I make it case insensitive?

dbassett74
11 Sep 2009, 6:31 AM
Okay, I think you can accomplish this using the Ext.util.Format.lowercase() on both values. Would this be the best way??

Condor
11 Sep 2009, 6:35 AM
A regexp is faster, e.g.

var regexp = new RegExp('^' + name + '$', 'i');
store.filterBy(function(r){
return regexp.test(r.get('project').name);
});