DataTable 初始化为“无结果可显示”,但 dt-length、dt-search、dt-info 和 dt-paging 正在显示,并且 dt-paging NaN 作为 data-dt-idx

问题描述 投票:0回答:1

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":[]}

我期待的只是一个没有过滤器和分页的显示表格,因为表格没有要显示的结果。

jquery datatables datatables-2
1个回答
0
投票

看起来好像您正在使用服务器端数据。如果从结果集中删除

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"
        },
        ...
    ]
}
© www.soinside.com 2019 - 2024. All rights reserved.