How to determine which column was clicked in a table using tablesorter?

I use jQuery and tablesorter to add column sorting to my data on the page.

I want to write down which column was sorted. How to determine which column was clicked? Is there an event I can connect to?

+3
source share
3 answers

I ended up using the sortEnd event and checked for the presence of the .sorted-az and .sorted-za 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");
});
+1
source

click .tablesorter .header , .

+3

click th:

$('#table').delegate('th', 'click', function(e) {
  //e.target will point to the header that was clicked
});
+1
source

Source: https://habr.com/ru/post/1775104/


All Articles