PDA

View Full Version : [CLOSED-1315] store.filter does not work ?



angel.ignacio.colmenares
6 Oct 2010, 8:11 AM
hi,

i' am getting unexpected results using store.filter method,
this is my code:



var myData= [
['Ed', 24], ['Ed',25], ['Ed', 26],
['xav', 21], ['xav', 22], ['xav', 23],
['ED', 24], ['ED', 25], ['ED', 26],
['Eddi', 24] , ['Eddi', 25], ['Eddi', 26] ];

var store= new Ext.data.Store();

var store = new Ext.data.ArrayStore({
fields: [
{name: 'name'},
{name: 'age', type: 'int'}
]
});

store.loadData(myData);
console.log(store.getCount()); //returns 12 ok

// taken from http://dev.sencha.com/deploy/dev/docs/
store.filter([
{
property : 'name',
value : 'Ed',
anyMatch : true, //optional, defaults to true
caseSensitive: true //optional, defaults to true
},
//filter functions can also be passed
{
fn : function(record) {
return record.get('age') == 24
},
scope: this
}
]);
console.log(store.getCount()); // return 12 wrong. must be 2 !!!


// using only RegExp seems to work fine
store.filter('name', new RegExp('ed') );
console.log(store.getCount()); //returns 0 ok

store.filter('name', new RegExp('Ed') );
console.log(store.getCount()); //returns 6 ok

store.filter('name', new RegExp('^Ed$') );
console.log(store.getCount()); //returns 3 ok

store.filter('name', new RegExp('^Ed','i') );
console.log(store.getCount()); //returns 9 ok

// but this does not work:

store.filter('name', 'ed', false,false ); // anyMatch : false , caseSentive:false
console.log(store.getCount()); // return 9 wrong. must be 0

store.filter('name', 'Ed', false,false ) ; // anyMatch : false , caseSentive:false
console.log(store.getCount()); // return 9 wrong. must be 6


what is wrong in this code ?
thanks !

meroy
15 Oct 2010, 9:58 AM
Confirmed. The 2nd test above is working with the current SVN release. The last 2 are failing.



store.filter('name', 'ed', false,false ); // anyMatch : false , caseSentive:false
console.log(store.getCount()); // return 9 wrong. must be 0

store.filter('name', 'Ed', false,false ) ; // anyMatch : false , caseSentive:false
console.log(store.getCount()); // return 9 wrong. must be 6

Condor
15 Oct 2010, 10:20 AM
The answers are correct! Your are searching with caseSensitive:false.

meroy
15 Oct 2010, 2:13 PM
The answer must be 6 for both due to false being passed for anyMatch.

angel.ignacio.colmenares
15 Oct 2010, 4:05 PM
setting anyMatch = true or anyMatch = false does not chage anything :same value =9 is this correct?

store.filter('name', 'Ed', true,false ) ; anyMatch=true,
console.log(store.getCount()) // returns 9
store.filter('name', 'Ed', false,false ) ; anyMatch=false
console.log(store.getCount()) // returns 9 . what role does anyMatch play ?

Condor
17 Oct 2010, 7:21 AM
anyMatch=false means match field starting with value.
anyMatch=true means match field containing value.

Your dataset is not a good testcase for anyMatch, because the store only contains values that either start with 'Ed' or don't contain the value at all.

angel.ignacio.colmenares
18 Oct 2010, 5:37 AM
thanks for your answer.
i see now where is my problem!!

only one more question:
what about first case using filter function : why getCount() returns 12 ?

Condor
18 Oct 2010, 6:04 AM
It doesn't. It returns 2.

ps. Regarding anyMatch: Where you in fact looking for the 'exactMatch' option?

angel.ignacio.colmenares
18 Oct 2010, 7:30 AM
hi condor,

yes, it returns 2, my mistake

and yes 'exactMatch' option was that i needed

thanks for your help

meroy
18 Oct 2010, 8:56 AM
Thanks Condor for the clarification. Marking this thread as closed.