Results 1 to 3 of 3

Thread: How to use filter with multiple data ?

  1. #1
    Sencha User
    Join Date
    May 2010
    Location
    Belgium
    Posts
    216
    Answers
    4

    Default How to use filter with multiple data ?

    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:

    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

  2. #2
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106

    Default

    You'll probably need to use filterBy() instead, where you can do anything you want in the function passed to filterBy().

  3. #3
    Sencha User
    Join Date
    May 2010
    Location
    Belgium
    Posts
    216
    Answers
    4

    Default SOLVED

    Hi,

    Indeed I had to use the filterBy function.

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

    Code:
        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);
    
    
                });
            }
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •