gpt4 book ai didi

javascript - jquery 数据表服务器端分页不起作用

转载 作者:可可西里 更新时间:2023-11-01 13:10:02 25 4
gpt4 key购买 nike

我正在尝试使用服务器端处理在 php 项目上实现 jquery datatables,但分页不起作用,而且我在 firebug 控制台中没有任何错误。

页面简洁明了,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,它不会创建导航到下一页的链接。我附上了一张照片以便更好地理解,下一页/上一页按钮被禁用,它显示只有一页。

enter image description here

最佳答案

recordsFiltered 应该表示通过搜索框(以及任何其他)过滤器的记录数,而不是页面上的记录数。

您告诉 DataTables 只有 10 条相关记录,因此它不会尝试为其他 13 条设置分页。

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

关于javascript - jquery 数据表服务器端分页不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38212906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com