Skip to content

Instantly share code, notes, and snippets.

@antislice
Last active June 28, 2017 05:45
Show Gist options
  • Save antislice/096b4b850d6f9e48887ce8be671628f6 to your computer and use it in GitHub Desktop.
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
// 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');
});
@antislice
Copy link
Author

Borrowed from a SO answer

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