I am using php
and this query select * from table
and the result I want to show in jquery
datatable
in server side processing means I want to use jquery
datatable
's own ajax
method. I have all total 58 rows. So by default I should have 6 page. 10 rows per page. Data is coming and is shown in the table. but with wrong pagination.
Actually it shows all 58 rows in the first page and also showing 6 pagination buttons. If I click on anything nothing is working. searching and sorting not working.
I am not pasting the sql
code here but the I am pasting the procedural code of php
here.
php
code:
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
code:
$(document).ready(function(){
$('#logs_table').DataTable( {
"processing": true,
"serverSide": true,
ajax: {
url: '../app/getData.php',
type: "POST"
}
} );
});
html
code:
<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>
I have attached an image of the final result.Table Image here