jquery search works for one column instead of the whole html table -
jquery search works for one column instead of the whole html table -
just want add together search possibility loaded table using jquery , code below works first column only. create work cells. please check code , help me find mistake:
here html code:
<span id="search"></span>
here js code:
$("#search").on("keyup", function () { var value = $(this).text(); $("table tr").each(function (index) { if (index != 0) { $row = $(this); $row.each(function () { var cell = $row.find("td").text(); if (cell.indexof(value) != 0) { $(this).hide(); } else { $(this).show(); } }); } }); });
i don't think need $row.each you're in each, seek each on columns instead:
$("#search").on("keyup", function () { var value = $(this).text(); $("table tr").each(function (index) { if (index != 0) { $row = $(this); $row.find("td").each(function () { var cell = $(this).text(); if (cell.indexof(value) != 0) { $(this).hide(); } else { $(this).show(); } }); } }); });
edit:
http://jsfiddle.net/rn8dsnwm/2/
$("#search").keyup(function () { var value = $(this).val(); if (value.length){ $("table tr").each(function (index) { if (index != 0) { $row = $(this); $row.find("td").each(function () { var cell = $(this).text(); if (cell.indexof(value) < 0) { $row.hide(); } else { $row.show(); homecoming false; //once it's shown don't want hide on next cell } }); } }); } else{ //if empty search text, show rows $("table tr").show(); } });
jquery
Comments
Post a Comment