Skip to content

Instantly share code, notes, and snippets.

@IOExceptional
Created June 11, 2015 15:05
Show Gist options
  • Save IOExceptional/0f7cd11a0890d14c9fc6 to your computer and use it in GitHub Desktop.
Save IOExceptional/0f7cd11a0890d14c9fc6 to your computer and use it in GitHub Desktop.
A simple, effective multi-dimensional row filtering script
var filter;
(function () {
filter = function (searchBox, targetClass) {
var value = searchBox.value;
var hiddenClass = targetClass + "SearchHidden";
//Nothing in the box, remove <targetclass>searchhidden class
if (value.length < 1) {
$("." + hiddenClass).removeClass(hiddenClass);
return;
}
var targets = $("." + targetClass);
console.log(targets);
for (var i = 0; i < targets.length; i++) {
var currentTarget = $(targets[i]);
var parent = currentTarget.closest(".row");
if (!currentTarget.text().trimLeft().startsWith(value)) {
$(parent).addClass(hiddenClass);
} else {
$(parent).removeClass(hiddenClass);
}
}
};
})();
@anupsaund
Copy link

YES son!

@anupsaund
Copy link

Consider changing starts with to a match?

http://www.w3schools.com/jsref/jsref_match.asp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment