我有一个 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 }
]
});
});
这是我一直在工作的内容:http://datatables.net/usage/columns
最佳答案
这应该可以满足您的需求
$(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 }
]
});
});
关键是aaSorting
选项。由于某种原因,它不在他的“主要”使用页面中...您可以在这里找到它 http://datatables.net/ref
关于jquery数据表默认排序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12410446/