我正在获取发票表中的数据,但是我想对数据进行排序 这是我的代码:
var oTable = $('#ks-datatable').DataTable({
'processing': false,
'serverSide': true,
"searching": false,
/*"bLengthChange": false,*/
'ajax': '{{route('invoice.index')}}',
columns: [
{data: 'id', name: 'id'},
{data: 'client_name', name: 'client_name'},
{data: 'invoice_number', name: 'invoice_number'},
{data: 'date', name: 'date'},
{data: 'created_at', name: 'created_at'},
{data: 'amount', name: 'amount'},
{data: 'action', name: 'action', searchable: false},
]
});
答案 0 :(得分:2)
在数据表中的使用顺序:
"ordering":'true'
"order": [columnNumber, 'orderType'],
示例
....
"ordering":'true'
"order": [0, 'desc'],
您的代码将是:
var oTable = $('#ks-datatable').DataTable({
'processing': false,
'serverSide': true,
"searching": false,
/*"bLengthChange": false,*/
'ajax': '{{route('invoice.index')}}',
"ordering":'true',
"order": [0, 'desc'],
columns: [
{data: 'id', name: 'id'},
{data: 'client_name', name: 'client_name'},
{data: 'invoice_number', name: 'invoice_number'},
{data: 'date', name: 'date'},
{data: 'created_at', name: 'created_at'},
{data: 'amount', name: 'amount'},
{data: 'action', name: 'action', searchable: false},
]
});