Created
June 11, 2015 15:05
-
-
Save IOExceptional/0f7cd11a0890d14c9fc6 to your computer and use it in GitHub Desktop.
A simple, effective multi-dimensional row filtering script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider changing starts with to a match?
http://www.w3schools.com/jsref/jsref_match.asp