Filter A Store With Array Of Values From One Property With Extjs
I'm trying to apply a constraint on combobox. It's half-working at the moment. On the combobox, I have this listener: [...] listeners: { 'focus': function (comb
Solution 1:
Each filter is applied one after the other on the previously filtered data set, so your code implements a logical AND. That's why all values are filtered out...
Here's an example using filterBy
to accept any value that is in your array:
function (combo, value) {
var orgComboVal = Ext.getCmp('Org1')
var values = orgComboVal.getValue();
if (values != null) {
store.clearFilter(false);
if (Ext.isArray(values)) {
store.filterBy(function(record, id) {
return Ext.Array.contains(values, record.get('code_organisme'));
});
} else {
record.get('code_organisme') === values;
}
} else {
store.clearFilter(true);
}
}
Or you could also use a regex with the filter
method:
function (combo, value) {
var orgComboVal = Ext.getCmp('Org1')
var values = orgComboVal.getValue();
if (values != null) {
var filterValue = Ext.isArray(values)
? newRegExp('^(?:' + Ext.Array.map(values, function(value){returnExt.escapeRe(value)}).join('|') + ')$')
: values;
store.clearFilter(false);
store.filter('code_organisme', filterValue);
} else {
store.clearFilter(true);
}
}
Concerning your error, arrays indeed don't have a split
method. Strings can be split into an array. Arrays, on their side, can be joined into a string...
Solution 2:
Try This....
var getOrgValue = "5,9,4"; // array of value
reseaulist.filterBy(function(rec, id) { return getOrgValue.indexOf(rec.get('code_organisme')) !== -1; });
Post a Comment for "Filter A Store With Array Of Values From One Property With Extjs"