2016-07-05 134 views
3

我想在一个php项目上使用服务器端处理实现jquery datatables,但分页不起作用,我在萤火虫控制台中没有错误。jquery datatable服务器端分页不起作用

的页面是简单和直接的,这里是html代码:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/datatables.min.css"/> 
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/datatables.min.js"></script> 

</head> 

<body> 
<table class="table"> 
    <thead> 
    <tr> 
    <th col-data="item_id">Item Id</th> 
    <th col-data="name">Name</th> 
    </tr> 
    </thead> 
</table> 

<script type="text/javascript"> 

    $(document).ready(function() { 
    var dataTable = $('.table').DataTable({ 
     "processing": true, 
     "serverSide": true, 
     "buttons": [], 
     "order": [], 
     "ajax":{ 
     url :"{{ url('stock_acc_get') }}", // json datasource 
     type: "post", 
     } 
    }); 

    }); 
</script> 

</body> 

</html> 

这是贴在服务器上的数据(在Firebug控制台查看):

columns[0][data]  0 
columns[0][name]  
columns[0][orderable]  true 
columns[0][search][regex] false 
columns[0][search][value] 
columns[0][searchable]  true 
columns[1][data]  1 
columns[1][name]  
columns[1][orderable]  true 
columns[1][search][regex] false 
columns[1][search][value] 
columns[1][searchable]  true 
draw 1 
length 10 
search[regex] false 
search[value] 
start 0 

这里是从服务器JSON响应:

{ 
    "draw":1, 
    "recordsTotal":23, 
    "recordsFiltered":10, 
    "data": [ 
    ["100018","Test Acc"],["100019","Test Acc 2"], 
    ["100020","Test Acc 3"],["5845645","Optional 1"], 
    ["56456456","Optional 2"],["541515","Optional 3"], 
    ["845812","Optional 4"],["103646","Belte Setesdal"], 
    ["103647","Belte Setesdal"],["103681","Belte Sigdal-Eggedal"] 
    ] 
} 

的页被设置为显示10条记录。 记录总数为23,并且不会创建链接以导航到下一页。为了更好理解,我附上了一张照片,Next/Previous按钮被禁用,它显示我只有一页。

enter image description here

回答

6

recordsFiltered应该代表的是通过搜索框过滤器,页面上没有记录的数量(与其他一起)的记录数。

你告诉的数据表,目前只有10个相关记录,所以它不会试图建立对其他13

传呼看第三数据表FAQ post(在服务器端处理类) ,或链接在该帖子中的Server-side processing页面以获取更多信息。

+0

链接到'常见问题'是真的很有帮助。 –

0

主要是recordsFiltered正在创建分页。所以通过这个参数在您的表中的数据总数recordsFiltered