Last active
June 28, 2017 05:45
-
-
Save antislice/096b4b850d6f9e48887ce8be671628f6 to your computer and use it in GitHub Desktop.
Filtering table rows w/ jquery, and updating the "selected" style on the filter labels
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
// Filter Row Script | |
// ........................................ | |
$('.sidebar a').on('click', function(e){ | |
e.preventDefault(); | |
var condition = $(this).data('filter'); | |
//get all trs from tbody | |
var trs = $(".main-messaging-content").find("tbody tr"); | |
trs.hide(); | |
//Filter all trs from tbody | |
trs.filter(function (i, v) { | |
if ($(this).data("status") == condition) { | |
return true; | |
} | |
if ($(this).data("urgent")) { | |
return true; | |
} | |
return condition == "all"; | |
}) | |
//just show the row if it fits the criteria | |
.show(); | |
var prev = $('a.selected'); | |
$(this).addClass('selected'); | |
prev.removeClass('selected'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Borrowed from a SO answer