我刚刚开始使用 Christian Bach 优秀的 TableSorter 插件,我需要获取列的当前排序方向。我有几个专栏:
- 身份证
- 姓名
- 类别
ID 和名称使用
设置为不可排序headers: { 0: {sorter: false}, 1: {sorter: false} }
我在“名称”上添加一个单击处理程序,以便它在“类别”列上触发排序事件。使用示例“Sort table using a link outside the table ”,我能够获取名称 header 来触发类别排序 - 但它是硬编码为朝一个方向排序。
如何让它查看类别列当前排序的当前方向,并按相反方向排序? (我可以处理翻转值;由于排序顺序是 0 或 1,我可以对值进行异或以获得相反的值,例如 var sort; sort ^= sort;
——我的问题是如何获取当前值。
以下是当前在“名称”列上设置点击处理程序的代码:
$("#nameCol").click(function() {
var sorting = [[2, 0]]; /* sort 3rd col (Category) descending */
$("#SearchResults").trigger("sorton", [sorting] ); /* SearchResults is the ID of the sortable table */
return false; /* cancel default link action on a#nameCol */
});
谢谢!
最佳答案
您可以使用内置的 sortEnd
事件来获取 sortOrder,如下所述:https://stackoverflow.com/a/4150187/363155
$('#yourtableId').on('sortEnd', function(event) {
// Prints the current sort order to the console
console.log(event.target.config.sortList);
});
关于jquery - 如何从tablesorter插件获取当前排序顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1955980/