I found this nice little script to allow a textbox to filter a table client side:
var gridSearch=’#’+'<%= gridSearch.ClientID %>’;
$(gridSearch).keyup(function () {
//split the current value of searchInput
var data = this.value.toUpperCase().split(” “);
//create a jquery object of the rows
var jo = $(“#grdSpreadSheet”).find(“tr”);
if (this.value == “”) {
jo.show();
return;
}
//hide all the rows
jo.hide();
//Recursively filter the jquery object to get results.
jo.filter(function (i, v) {
var $t = $(this);
for (var d = 0; d < data.length; ++d) {
if (($t.text().toUpperCase().indexOf(data[d]) > -1))
{
return true;
}
}
return false;
})
//show the rows that match.
.show();
}).focus(function () {
this.value = “”;
$(this).css({
“color”: “black”
});
$(this).unbind(‘focus’);
}).css({
“color”: “#C0C0C0”
});
I’ve tried to change the conditional statement in the way i would in other languages to always show the first row:
if ( (d==0) || ($t.text().toUpperCase().indexOf(data[d]) > -1) )
now no filtering goes on what so ever…. so the syntax or work flow is wrong. Can someone please show me the correct syntax and possible explain why I have it wrong?
Thanks