几个小时以来,我一直在努力解决这个问题,但没有成功。当我加载我的表时,我需要它在第一个 col 上对 desc 进行排序。这是我所拥有的,但没有运气。
/**
* Makes the table in the tabs for reports
*
* @param array Holds the data for datatable.
**/
var makeTabTable = function(tableData){
$("#tab_active_reg").dataTable({
bJQueryUI : true,
bDestroy : true,
aoColumns : [
{"sTitle" : "Seen", "sWidth" : "50px", "asSorting": [ "desc"]},
{"sTitle" : "Sold", "sWidth" : "50px"},
{"sTitle" : "Name", "sWidth" : "240px"}
],
aaData : tableData
});
$('.tabsComponent').find('.fg-toolbar').empty();
};
最佳答案
只需将此选项添加到 dataTable()
调用中:
aaSorting : [[0, 'desc']]
所以在你的情况下:
$("#tab_active_reg").dataTable({
bJQueryUI : true,
bDestroy : true,
aaSorting : [[0, 'desc']],
aoColumns : [
{"sTitle" : "Seen", "sWidth" : "50px"},
{"sTitle" : "Sold", "sWidth" : "50px"},
{"sTitle" : "Name", "sWidth" : "240px"}
],
aaData : tableData
});
可以看到,它是一个[colnumber, sortdirection]
的数组,所以可以指定多个。
关于javascript - 让您的 jquery 数据表按第一列对 DESC 进行排序。或者将另一列设置为其默认排序方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11333507/