javascript - jquery-datatables 多列排序方向

标签 javascript sorting jquery-datatables

使用 jquery-datatables。

示例:http://jsfiddle.net/b2fLye17/17/

$('#example').DataTable({

    filter:false,
    columnDefs: [
                    {
                        targets: [1],//when sorting age column
                        orderData: [1,2] //sort by age then by salary
                    } 
                ]
});

当您单击年龄列时,表格按年龄升序排序,然后按薪水升序排序。

我有什么选择可以让它按年龄升序排序然后按薪水降序排序?

谢谢!

------------------------ 编辑 1 ------------------ --

澄清:当年龄列按升序排序时,它应该按年龄升序排序,然后按薪水降序排序。当年龄列降序排序时,它应该按年龄降序排序,然后按薪水升序排序

------------------------ 编辑 2 ------------------ --

期望结果的图片enter image description here

最佳答案

使用

$(document).ready(function() {

    $('#example').DataTable({

        filter:false,
        columnDefs: [
                        {
                            orderData: [[1, 'asc'], [2, 'desc']]//sort by age then by salary
                        }
                    ]
    });
});

JS fiddle http://jsfiddle.net/b2fLye17/13/

关于javascript - jquery-datatables 多列排序方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27527160/

相关文章:

javascript - 在 datatables.net 上调用 fnGetPosition 会抛出 "Cannot call method ' toUpperCase' of undefined"错误

javascript - 使用 jquery 或 javascript 拆分具有不同分隔符的字符串

javascript - 处理长文本的聪明方法

javascript - 在 javascript 中递归构建 promise 链 - 内存注意事项

java - 如何有效地对一个数组进行排序

java - 选择排序不在Java中排序

javascript - 如何用JS改变href属性的值?

javascript - 按字母顺序对JSON排序(最后为空值)

Django:使用数据表

jquery-datatables - deferRender 不适用于 5,000 多行 ajax 源表/滚动器插件(数据表)