DataTable分页不起作用

时间:2015-10-13 22:20:12

标签: javascript php pagination datatables

我使用DataTable通过serverSide模式和ajax显示我的数据 一切都很好,但分页不起作用。

您可以查看以下代码:

HTML:

<table id="table" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <td>ID</td>
            <td>First name</td>
            <td>Last name</td>
            <td>Email</td>
        </tr>
    </thead>
    <tbody></tbody>
</table>

使用Javascript:

$(document).ready(function () {
    $('#table').DataTable({
        serverSide: true,
        ajax: {
            url: '<?php echo base_url(); ?>folder/class/method'
        },
        processing: true,
        scrollY: 370,
        paging: true,
        bJQueryUI: true
    });
});

从服务器(JSON)返回的数据如下:

{
    "draw": 1,
    "recordsTotal": 1208,
    "recordsFiltered": 10,
    "data": [
        ["1", "pando", "rewar", "pando@hotmail.com"],
        ["2", "chori", "raon", "m_chori@hotmail.com"],
        ["3", "Gorbat", "horiz", "horiz_555@yahoo.com"],
        ["4", "martin", "sokza", "martin_em5@gmail.com"],
        ["5", "dooz", "solda", "solda_m@gmail.com"],
        ["6", "maro", "meza", "r_meza@hotmail.com"],
        ["7", "nod", "ion", "nod_eam@yahoo.com"],
        ["8", "kaz", "loob", "kaz_007@hotmail.com"],
        ["9", "Barbara", "Elliott", "adipiscing@nonmassanon.org"],
        ["10", "Kendall", "Nathaniel", "ante.blandit@scelerisque.edu"]
    ]
}

DataTable的所有组件都可以正常工作,但不是分页。

1 个答案:

答案 0 :(得分:0)

参数recordsFiltered必须等于recordsTotal,除非用户执行了搜索。有关已发送和已接收参数的详细信息,请参阅manual

另外,请确保您在响应中返回相同的draw参数值。在JSON response draw参数值必须与requestdraw参数的值匹配。