As the title states. I'm using jQuery to do the magic. I've used a custom Contains
extension to the selectors as follows:
jQuery.expr[':'].Contains = function(a, i, m) {
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
which I found on the interwebs. It works fine. I'm using it in conjunction with the following:
$("#txtSurname, #txtForename").keyup(function() {
var forenameVal = $("#txtForename").val();
var surnameVal = $("#txtSurname").val();
$("#tblEmployees tr").show();
if (forenameVal.length > 0) { $("#tblEmployees tr td:nth-child(1):not(:Contains('" + forenameVal + "'))").parent().hide(); }
if (surnameVal.length > 0) { $("#tblEmployees tr td:nth-child(2):not(:Contains('" + surnameVal + "'))").parent().hide(); }
});
However, this is highly inefficient and with a table of 500 rows it struggles tremendously. My jQuery uber-ninja-skills aren't as great as the next developer when it comes to writing efficient selectors, thus I was wondering if there's a better way to do this?