1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    3
    Vote Rating
    0
    nicky.esh is on a distinguished road

      0  

    Exclamation Search Function cannot restore the orignal list

    Search Function cannot restore the orignal list


    Hi all,


    I have this problem with the existing search list code from Internet which I think you guys might be familiar with it.

    My issue is once I start searching by keying one character at a time, the store will be filtered correctly. But when I erase all characters from the search field or click on the X button on the right side, my original store is not appearing on the list. It should display the original all data in the list (store) when I cancel my search and it has to compare with original list every single time I key in a character one after. Somehow it doesn't compare to original list each time I key in a character.

    Example: the list has ['Terry', 'Amanda', 'Zee Avi', 'Coldplay', 'ABC']

    when I key in 'a', the list cut down to ['ABC', 'Amanda', 'Zee Avi'', 'Coldplay']
    then I continue to key in 'ab', the list [] return empty which is correct. But when i backspace/delete one character at a time, the list is not functioning well. It should search again to original list and get the result back.

    So here's the code in controller:
    Code:
         if (!value) {
            	store.filterBy(function() {
                           return true;
                           });
            } else {
    	        var searches = value.split(' '),
    	        regexps  = [],
    	        i;
    	        
    	        for (i = 0; i < searches.length; i++) {
    		        if (!searches[i]) return;
    		        regexps.push(new RegExp(searches[i], 'i'));
    	        };
    	        
    	        store.filterBy(function(record) {
    	                       var matched = [];
    	                       
    	                       for (i = 0; i < regexps.length; i++) {
    		                       var search = regexps[i];
    		                       
    		                       if (record.get('title').match(search) ) 
    		                    	   matched.push(true);
    		                       else 
    		                    	   matched.push(false);
    	                       };
    	                       
    	                       if (regexps.length > 1 && matched.indexOf(false) != -1) {
    	                    	   return false;
    	                       } else {
    	                    	   return matched[0];
    	                       }
    	        });
            }
    which line should I change in order to get back the correct result and should be only keyup event? How about if I backspace/delete one character at a time?

    Any idea?

    Thanks
    Regards
    Nicky

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,010
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    store.clearFilter() should work if there is no value instead of filterBy.

    What ST2 version are you using?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread