PDA

View Full Version : [FIXED-246] Data Store Filtering



RWaters
27 Aug 2010, 12:34 PM
Platform tested against:

iOS 3.x
iOS 4
Chrome


Description:

The data store attempts to push all of the filtering off to Ext.util.MixedCollection (which is a good idea imo), but the createFilterFn it uses doesn't properly handle being passed a Model object.


Test Case:



Ext.setup({
onReady : function() {
Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});
var store = new Ext.data.Store({
model: 'Contact',
sorters: 'firstName',
data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Jamie', lastName: 'Avins'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Dave', lastName: 'Kaneda'},
{firstName: 'Michael', lastName: 'Mullany'},
{firstName: 'Abraham', lastName: 'Elias'},
{firstName: 'Jay', lastName: 'Robinson'},
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Jamie', lastName: 'Avins'},
{firstName: 'Aaron', lastName: 'Conran'},
{firstName: 'Dave', lastName: 'Kaneda'},
{firstName: 'Michael', lastName: 'Mullany'},
{firstName: 'Abraham', lastName: 'Elias'},
{firstName: 'Jay', lastName: 'Robinson'},
{firstName: 'Zed', lastName: 'Zacharias'}
]
});
new Ext.List({
fullscreen: true,
tpl: '<tpl for="."><div class="contact"><strong>{firstName}</strong> {lastName}</div></tpl>',
itemSelector: 'div.contact',
store: store,
dockedItems:[{
xtype: 'toolbar',
dock: 'top',
items:[{
id: 'search',
xtype: 'textfield',
flex: Ext.platform.isPhone ? 9.2 : 9.8,
listeners: {
keyup: {
fn: function(fld, e) {
var val = fld.getValue();
if (val == '') {
return store.clearFilter();
}
store.filter({
property: 'firstName',
value: val,
anyMatch: true,
caseSensitive: false
});
},
buffer: 250
}
}
},{
iconCls: 'delete',
ui: 'mask',
flex: Ext.platform.isPhone ? 0.8 : 0.2,
handler: function() {
Ext.getCmp('search').reset();
store.clearFilter();
}
}]
}]
});
}
});




Steps to reproduce the problem:

type anything into the search box


The result that was expected:

the data store to be filtered on characters entered


The result that occurs instead:

a filter function is created that improperly attempts to access the data and winds up always returning false blanking out the List


Possible fix:
In Ext.util.MixedCollection


createFilterFn : function(property, value, anyMatch, caseSensitive, exactMatch) {
if (Ext.isEmpty(value, false)) {
return false;
}
value = this.createValueMatcher(value, anyMatch, caseSensitive, exactMatch);
return function(r) {
return value.test(r.isModel ? r.data[property]: r[property]);
};
}


Additional Note

There is a functioning createFilterFn method in Ext.data.Store, it's currently used only by the find method, if you implement the above you could drop the duplicate method from the Store entirely and change find.



find : function(property, value, start, anyMatch, caseSensitive) {
var fn = this.data.createFilterFn(property, value, anyMatch, caseSensitive);
return fn ? this.data.findIndexBy(fn, null, start) : -1;
},

Jamie Avins
30 Aug 2010, 9:12 AM
Thank you for the detailed report.

edspencer
3 Sep 2010, 5:49 PM
This has now been fixed and will appear in the next release