jQuery:3.7.1 数据表:2.0.6
$(#dtTable).DataTable({
paging: true,
ordering: true,
serverSide: true,
searching: true,
// ordering of the table default [column,direction]
order: [[0, "desc"]],
ajax: {
url: "/ajax_url",
type: "POST"
},
pagingType: 'simple_numbers',
responsive: true,
processing: true,
lengthMenu: [
[5, 10, 25, 50],
[5, 10, 25, 50],
],
pageLength: 10,
bSort: true,
searchDelay: 1500,
columnDefs: [
{ responsivePriority: 1, targets: 0 },
{ responsivePriority: 2, targets: -1 },
]
})
response: {"draw":1,"data":[]}
我期待的只是一个没有过滤器和分页的显示表格,因为表格没有要显示的结果。
看起来好像您正在使用服务器端数据。如果从结果集中删除
draw
会发生什么?根据文档,您的结果数据中可能缺少一些值:https://datatables.net/manual/server-side#Example-data - 特别是recordsTotal
和recordsFiltered
。
这是文档中的示例:
{
"draw": 1,
"recordsTotal": 57,
"recordsFiltered": 57,
"data": [
{
"DT_RowId": "row_3",
"DT_RowData": {
"pkey": 3
},
"first_name": "Angelica",
"last_name": "Ramos",
"position": "System Architect",
"office": "London",
"start_date": "9th Oct 09",
"salary": "$2,875"
},
{
"DT_RowId": "row_17",
"DT_RowData": {
"pkey": 17
},
"first_name": "Ashton",
"last_name": "Cox",
"position": "Technical Author",
"office": "San Francisco",
"start_date": "12th Jan 09",
"salary": "$4,800"
},
...
]
}