DataTables 1.10 - Not Showing Results

痞子三分冷 提交于 2019-12-11 09:34:59

问题


This is my setup.

Javascript/jQuery:

$('#list').dataTable({
    paging: false,
    serverSide: true,
    ajax: {
        url: "/search/",
        data: function (d) {
            return $.extend({}, d, {
                lid: Label.selectedId
            });
        }
    }
});

HTML

<table id="list" class="table table-striped" width="100%">
    <thead>
    <tr>
        <th>Title</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>URL</th>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>

JSON Response

{"data": [["Test", "", "", ""]], "recordsTotal": 1, "draw": 1, "recordsFiltered": 1}

It is getting called manually by doing this:

$('#list').DataTable().ajax.reload();

But the table does not change. I've done this many times with DataTables 1.9 without a hitch -- any ideas?


UPDATE

I discovered if I turn off serverSide, it works.


回答1:


I found the problem. It was with the draw in the JSON response. It was always 1.

If you use serverSide: true, that means it is going to send draw as a variable, and it must be returned.

More information here: http://datatables.net/manual/server-side



来源:https://stackoverflow.com/questions/24171141/datatables-1-10-not-showing-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!