Ext.data.Store Incorrectly Filters Multiple Fields and Values In Sencha Touch
Posted by admin on
September 26, 2012
I bet you used the filter() function to do it, right?
This function only works if you specify one field or an array of fields to use in filtering out results based on 1 search text. If there is more than 1 value to consider in filtering entries in the store, you will have to use the filterBy() function for custom and complex scenarios.
Check out this sample code.
store.filterBy(function(record, id) { if (record.get('fieldname1').indexOf('searchkey1') > -1 && record.get('fieldname2').indexOf('searchkey2') > -1) return true; });
The code filters entries in the store where a model’s field name labeled fieldname1 and fieldname2 has a substring of searchkey1 and searchkey2 respectively. That is how you should do it.
This won’t work.
var op = new Array(); op.push({ property: 'fieldname1', value: 'searchkey1' }); op.push({ property: 'fieldname2', value: 'searchkey2' }); store.filter(op);









