我正在使用 JQuery tablesorter v 2.0。我目前的设置是这样的
$("#myTable").tablesorter({
sortList: [[4,0]]
});
但是我如何将默认排序顺序设置为始终是表中的最后一列?硬编码数字可能不理想的原因是因为我动态生成表数据,有时表有五列,有时有六列。
最佳答案
您可以计算表中标题的数量,并使用它来获取最后一列索引。例如:
// Get the number of "th" within the first "tr":
var columnCount = $('table tr:first').children('th').length;
$("#myTable").tablesorter({
sortList: [[columnCount - 1, 0]]
});
关于jquery - 如何使 jQuery 表排序器始终在最后一列进行初始排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42094617/