Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
表格中的信息有时已经排序,所以当用户点击标题时,插件会以相同的顺序再次对其进行排序,但看起来什么都没有发生。有没有办法检测信息是否已经排序?
我会在列标题元素上设置某种指标,即数据属性 data-sorted="true" 并在再次排序之前对其进行检查。这是一些示例 jQuery 代码:
$(".column-header").click(function(event) { event.preventDefault(); if (!$(this).data("sorted")) { // do sorting } });
如果要交替排序方向,可以使用不同的值:asc/desc。