/    Sign up×
Community /Pin to ProfileBookmark

Need to modify table row filter script to always show top (header) row

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rootMay 12.2016 — Your script is JQuery, see link in my signature for correct forum.
Copy linkTweet thisAlerts:
@TrainMay 13.2016 — Moved to the correct forum.
×

Success!

Help @noob2js spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...