jquery datatables默认排序不起作用

tur*_*2oh 10 jquery jquery-plugins

我有一个4列表,我希望用户可以排序前3个columsn,但不是第4个,这很好用.我还希望第3列默认按ASC顺序排序.这部分不起作用,我不能默认排序任何列,也无法弄清楚我的语法有什么问题:

$(document).ready(function() {
$(".table-sortable").dataTable({
    aaSorting: [],
    bPaginate: false,
    bFilter: false,
    bInfo: false,
    bSortable: true,
    bRetrieve: true,
    aoColumnDefs: [
        { "aTargets": [ 0 ], "bSortable": true },
        { "aTargets": [ 1 ], "bSortable": true },
        { "aTargets": [ 2 ], "asSorting": [ "asc" ], "bSortable": true },
        { "aTargets": [ 3 ], "bSortable": false }
    ]
}); 
});
Run Code Online (Sandbox Code Playgroud)

这是我一直在做的工作:http://datatables.net/usage/columns

BLS*_*lly 31

这应该可以满足您的需求

$(document).ready(function() {
    $(".table-sortable").dataTable({
        aaSorting: [[2, 'asc']],
        bPaginate: false,
        bFilter: false,
        bInfo: false,
        bSortable: true,
        bRetrieve: true,
        aoColumnDefs: [
            { "aTargets": [ 0 ], "bSortable": true },
            { "aTargets": [ 1 ], "bSortable": true },
            { "aTargets": [ 2 ], "bSortable": true },
            { "aTargets": [ 3 ], "bSortable": false }
        ]
    }); 
});
Run Code Online (Sandbox Code Playgroud)

关键是aaSorting选项.出于某种原因,它不在他的"主要"用法页面中......你可以在http://datatables.net/ref找到它

  • 如果使用以下内容,我让它使用类名而不是列索引的唯一方法: 'aaSorting': [[$('.desc').index(), 'desc']] where '.desc'我想排序的列上的类。 (2认同)