PDA

View Full Version : How to use filter with multiple data ?



marxan
26 Jun 2012, 4:55 AM
Hello,

I'm trying to use filter method to select only data I need on the store.
I works with one data but as I use multipleselect my combo can have several values but I have no idea how I can use the filter with multiple value.

Does a property exists to do that?

Here is my code:


var store = Ext.getStore('MetrSeriesStore');
if (countries == '')
{
store.clearFilter();
}
else {
var countr = countries.toString();
var valueArray = countr.split(",");

for(var i=0; i<valueArray.length; i++){
store.filter("LABEISO",valueArray[i]);


}
}

Thanks in advance

friend
26 Jun 2012, 5:32 AM
You'll probably need to use filterBy() (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.Store-method-filterBy) instead, where you can do anything you want in the function passed to filterBy().

marxan
27 Jun 2012, 12:47 AM
Hi,

Indeed I had to use the filterBy function.

Here's the working code. I hope this could help.


getCountries: function (combo, rec, index) {

var store = Ext.getStore('MetrSeriesStore');


// If nothing selected, I removed all previously selected filter so I display all datas of my store
if (rec == '') {
store.clearFilter();
} else {
// a string that will contain the instruction to evaluate
var result;

// I put the selected value of my combo into an Array
var countr = rec.toString();
var valueArray = countr.split(",");

store.filterBy(function (s) {
/*
* For each value I will concatenate the result value in order to filter on several options
*/
for (var i = 0; i < valueArray.length; i++) {
if (i > 0) {
result = result + "|| s.get('LABEISO') =='" + valueArray[i] + "'";
} else {
result = "(s.get('LABEISO') == '" + valueArray[i] + "'";
}
}
/* I finish the string to have a string that will be a valid instruction
* Example if I selected Belgium and Denmark in my combo list:
* (s.get('LABEISO') == 'Belgium' || s.get('LABEISO') == 'Denmark');
*/
result = result + ");"

// I evaluate my string to execute it as an instruction
return eval(result);


});
}
}