How can I determine which column was clicked in a table using tablesorter?
I am using jQuery and tablesorter to add column sorting to my data on a page.
I want to to record which column was sorted. How can I determine which column was cl开发者_C百科icked? Is there an event that I can hook into?
Setting your own click event on the .tablesorter .header
should provide an easy way to getting the column clicked whilst avoiding conflicts with other tables
Simply assign a delegate to the table and catch click
events on th
elements:
$('#table').delegate('th', 'click', function(e) {
//e.target will point to the header that was clicked
});
I ended up using the sortEnd event and checking for the presence of the .sorted-a-z and .sorted-z-a classes to determine the sorted column.
table.bind("sortEnd", function () {
var checkSort = function (query, order) {
var column = table.find(query);
if (column.length == 1){
// Do stuff
}
};
checkSort("th.sorted-a-z", "descending");
checkSort("th.sorted-z-a", "ascending");
});
精彩评论