Created
June 17, 2011 19:22
-
-
Save jasonlong/1032098 to your computer and use it in GitHub Desktop.
Adding a class to <td> elements with jquery.tablesorter.js
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
$('table.sortable').tablesorter(); | |
$('table.sortable th').bind('click', function() { | |
// remove sorted class from all table cells and start fresh | |
$(this).closest('table').find('td.sorted').removeClass('sorted'); | |
// find out which column was clicked and add the sorted class to | |
// the <td> cells below it | |
var index = $(this).prevAll().length; | |
$(this).closest('table').find('tr').each(function(row) { | |
var cell = $(this).find('td:nth-child(' + parseInt(index+1) + ')').addClass('sorted'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment