【发布时间】:2017-07-25 11:36:07
【问题描述】:
我正在使用php 和这个查询select * from table 以及我想在服务器端处理中显示在jquery datatable 中的结果意味着我想使用jquery datatable 自己的ajax方法。我总共有 58 行。所以默认情况下我应该有 6 页。每页 10 行。数据即将到来,并显示在表格中。但分页错误。
实际上它在第一页显示了所有 58 行,还显示了 6 个分页按钮。如果我点击任何东西都不起作用。搜索和排序不起作用。
我没有在此处粘贴sql 代码,而是在此处粘贴php 的程序代码。
php代码:
require_once("logic/LogsDataLogic.php");
$ldl = new LogsDataLogic();
$data = $ldl->getDataByFromDateToDate();
$arr = [
"draw" => $_POST["draw"],
"recordsTotal" => count($data),
"recordsFiltered" => count($data),
"data" => $data
];
echo json_encode($arr);
jquery代码:
$(document).ready(function(){
$('#logs_table').DataTable( {
"processing": true,
"serverSide": true,
ajax: {
url: '../app/getData.php',
type: "POST"
}
} );
});
html代码:
<link href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" type="text/css" rel="stylesheet">
</head>
<body>
<table class="display" cellspacing="0" width="100%" id="logs_table">
<thead>
<tr>
<th>ID</th>
<th>User ID</th>
<th>Login Time</th>
<th>IP</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>User ID</th>
<th>Login Time</th>
<th>IP</th>
</tr>
</tfoot>
</table>
<!-- end here -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
我附上了最终结果的图片。Table Image here
【问题讨论】:
-
我认为您错过了导致数据表无法正常工作的表结构..请检查控制台..可能对您有所帮助..
-
我在这里添加了所有内容。您可以看到,但控制台中没有错误
标签: php jquery datatables