PDA

View Full Version : Multiple store filters not working, array in filter neither.



kevinv1990
7 Oct 2010, 7:00 AM
Hello all,

I have a Store named "datastore, which I want to filter on multiple values, at the moment I have:

datastore.filter([{"locatie", formlocatie},{"locatie", formlocatie}]);

but this is not working, also I tried:

datastore.filter({"locatie": formlocatie, "titel": formtrefwoord});

still no succes, I did in the API something about:filterBy( Function fn, [Object scope] ) : void

But I have no idea how to use it.

Kevin

evant
7 Oct 2010, 2:48 PM
Ext.regModel('Person', {
fields: ['name', 'age']
});

var s = new Ext.data.Store({
model: 'Person',
data: [{
name: 'Foo',
age: 1
}, {
name: 'Foo',
age: 2
}, {
name: 'Bar',
age: 1
}, {
name: 'Bar',
age: 2
}]
});

debugger;
s.filter([{
property: 'name',
value: 'Foo'
}, {
property: 'age',
value: 1
}]);
console.log(s.getCount());

iamcam
17 Nov 2010, 3:30 PM
Is there any way to search multiple fields via OR rather than AND?

One example that's coming to mind is searching through a large list of names. At times the user may want to use the search string to represent a first name, other times a last name.
In my own code, I tried something like this, but will almost always get an empty set unless the exact match is found in both first and last names.

store.filter([{
property: 'FirstName',
value: srch,
anyMatch: true,
},
{
property: 'LastName',
value: srch,
anyMatch: true,
}
]);

On a side note, I tried the store.getCount() method, but it returned zero every time, even before filtering the data. Maybe I'm missing something

evant
18 Nov 2010, 9:30 AM
You can use the filterBy method to do any kind of custom/complex filtering.

iamcam
19 Nov 2010, 10:35 AM
That did the trick! For anyone else curious about this, here's my code on the search field:


listeners: {
change: function(){
srch = this.getValue();

store.filterBy(function(record, id){
FirstName = record.get('FirstName');
LastName = record.get('LastName');

pattern = new RegExp(srch, 'gi');

if((pattern.test(FirstName) || pattern.test(LastName))){
return true;
}
});

store.sort(); //important to maintain proper sort order in the list
}
}