问题描述
jQuery Datatable在单击列标题上的排序顺序仅在asc(向下箭头)和desc(向上箭头)之间切换。即,
jQuery Datatable's sorting order on clicking column header toggles only between asc(Down Arrow) and desc(Up Arrow). i.e.,
1st-click ascending
2nd-click descending
3rd-click asc
4th-click desc
|| ||
|| ||
|| ||
|| ||
odd-click asc
even-click desc.
我想诱导这样的事情:
1st-click ascending
2nd-click descending
3rd-click no-sorting
4th-click asc
5th-click desc
6th-click no-sort
|| ||
|| ||
|| ||
|| ||
(n%3==1)-click asc
(n%3==2)-click desc
(n%3==0)-click no-sort.
有没有办法在jQuery dataTables中改变这种行为?请帮忙!
提前致谢。
Is there a way to change this behavior in jQuery dataTables? Please help!Thanks in advance.
推荐答案
哇,这很有意思。这应该做你需要的,虽然它不优雅:
Wow, that was interesting. This should do what you need though it's not elegant:
$('#example').on("order.dt", function () {
if(example.settings().order().length === 1){
var order = example.settings().order()[0];
var th = $("#example th:eq(" + order[0] + ")");
if(th.attr("data-sort-next") === "false"){
example.order([]).draw();
th.attr("data-sort-next", true);
}else{
if(order[1] === "desc"){
th.attr("data-sort-next", false);
}else{
th.attr("data-sort-next", true);
}
}
}
});
这个工作说明了发生了什么。基本上,您想要的是多列排序的开箱即用(如评论中所述)。我所做的是拦截排序,如果只有一列被排序,而不会弄乱多列排序。我将继续尝试改进它,但这应该适合你。
This working JSFiddle illustrates what's going on. Basically, what you want is available out of the box for multi-column sorting (as noted in the comments). What I've done is intercept the sorting if there's only one column being sorted, without messing up the multi-column sorting. I'll keep on trying to refine it but that should work for you.
这篇关于jQuery DataTables:我可以为Sort提供3种状态:ASC,DESC和NO_SORT吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!