PDA

View Full Version : hasMany association store filter. Bug?



styv
1 Jun 2014, 10:30 AM
Hello!

I have model with hasMany association (ExtJS 4.2.1.883):


Ext.define('App.model.Asset', {
extend: 'Ext.data.Model',

uses: [ ... ],
fields: [ ... ],

hasMany: [
{
name: 'devices',
model: 'App.model.Device',
foreignKey: 'assetId',
primaryKey: 'id'
}
]
});


After creating asset model automatically added filter to devices store:


exactMatch: true
filter: undefined
filterFn: undefined
initialConfig: { ... }
property: "assetId"
root: "data"
value: undefined


Next, I need to add some filters to the store and filter it (for unsaved asset model), but I get an error:


Uncaught TypeError: Cannot read property 'call' of undefined


into static method createFilterFn in Ext.util.Filter:


createFilterFn: function(filters) {
return filters && filters.length ? function(candidate) {
var isMatch = true,
length = filters.length,
i, filter;


for (i = 0; isMatch && i < length; i++) {
filter = filters[i];

if (!filter.disabled) {
isMatch = isMatch && filter.filterFn.call(filter.scope || filter, candidate);
}
}
return isMatch;
} : function() {
return true;
};
}


This is bug or am I doing something wrong?


P.S. Now I just changed createFilterFn method:


if (!filter.disabled && filter.filterFn)

funckye
4 May 2015, 8:34 PM
you can override the class instead of hand edit


Ext.override('Ext.util.Filter',{
statics:{
createFilterFn: function(filters) {
return filters && filters.length ? function(candidate) {
var isMatch = true,
length = filters.length,
i, filter;

for (i = 0; isMatch && i < length; i++) {
filter = filters[i];

if (!filter.disabled && filter.filterFn) {
isMatch = isMatch && filter.filterFn.call(filter.scope || filter, candidate);
}
}
return isMatch;
} : function() {
return true;
};
}
}
});