SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2013
    Posts
    26
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Live table searching (jquery)

    Hello,

    I have a small code to filter data depending on what users types in the input box and also a database with different kind of mobile phones.

    The plugin works fine aside from one little thing, for example ...i have "Samsung Galaxy S4 I9505".

    If the user type only " S4 " or "Samsung" the plugin works, but if the user type only "Samsung S4" the plugin not working anymore,because is missing the "galaxy" word, the user need to type the name of the mobile phone in the same order as is stored in the database, if is missing on word, the plugin not work anymore.

    How to modify this plugin to search for words in any order ...for example "Samsung S4" or "Samsung I9505"?

    Here is my code:

    Code:
    $(document).ready(function(){
    	$("#searchInput").keyup(function(){
    		
    		if( $(this).val() != "")
    		{
    			
    			$("#tablesorter-demo tbody>tr").hide();
    			$("#tablesorter-demo td:contains-ci('" + $(this).val() + "')").parent("tr").show();
    		}
    		else
    		{
    			
    			$("#tablesorter-demo tbody>tr").show();
    		}
    	});
    });
    
    
    $.extend($.expr[":"], 
    {
        "contains-ci": function(elem, i, match, array) 
    	{
    		return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
    		return (elem.textContent || elem.innerText || $(elem).text() || "").toUpperCase().indexOf((match[3] || "").toUpperCase()) >= 0;
    	}
    });

    Thank you

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,892
    Mentioned
    211 Post(s)
    Tagged
    12 Thread(s)
    Hi Norbert,

    The first thing that occurs to me is to split the search expression at the space and try and match the pieces against a regex.

    e.g.

    Code:
    var words = "Samsung Galaxy".split(" ");
    if (string.match(words[0]) && string.match(words[1])){
      // Whatever
    }
    Which plugin are you using?


Tags for this Thread

Bookmarks

Posting Permissions

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