The paved paths were a bit slow for my desk. I came up with another solution that seems much faster.
If you want to search in each cell, you can add an attribute to the cell (I used name-name), for example: <td data-name="john smith">John Smith</td> . Then you can use this javascript code:
$("#search").keyup(function() { var val = this.value.trim().toLowerCase(); if ('' != val) { var split = val.split(/\s+/); var selector = 'td'; for(var i=0;i<split.length;i++){ selector = selector+'[data-name*='+split[i]+']'; } $('tr').hide(); $(selector).closest('tr').show(); } else { $('tr').show(); } });
If you just want to search for strings for a single attribute, you can simply add the attribute to a string like <tr data-name="john smith"><td>John Smith</td><td>...</td></tr> and use the following:
$("#search").keyup(function() { var val = this.value.trim().toLowerCase(); if ('' != val) { var split = val.split(/\s+/); var selector = 'tr'; for(var i=0;i<split.length;i++){ selector = selector+'[data-name*='+split[i]+']'; } $('tr').hide(); $(selector).show(); } else { $('tr').show(); } });
Hope this helps!
Jose Castellanos
source share