I am using jQuery DataTables version 1.10.12. Below is my relevant code
// initialize datatable
jQuery('#taskTable').DataTable( {
"bProcessing": true,
"bServerSide": true,
"bInfo": true,
"bPaginate": true,
"bLengthChange":false,
"pageLength": 10,
"sAjaxDataProp":"serverPageDataModelBean.data"
});
Data is being displayed and pagination is working. However when I set "bInfo": true
I get the following message:
Showing 0 to 0 of 0 entries (filtered from NaN total entries)
and my Next button does not work. In serverPageDataModelBean I am sending {"recordsTotal":12,"recordsFiltered":12,"data":[]}
where data is not empty.
Can someone please tell me what is wrong?
I know this too late, but I'm posting this in case someone stumbles on this. The answer is you need to set serverside to false like this "serverSide": false.
Your server-side response is missing draw
parameter which should have the same value as the draw
parameter in the request. When that happens, jQuery DataTables discards the data.
draw
The draw counter that this object is a response to - from the
draw
parameter sent as part of the data request.
Return draw
parameter with the same value as draw
parameter from the request.
See Server-side processing - Returned data for more information.
If you are using serverside: true
option, then remove this or write serverside: false
for example:
$(document).ready(function() {
$('#example1').dataTable( {
"ajax": {
"url": "view_results",
"type": "POST"
},
'order':[]
} );
});
the response for empty data when handling on server side for example php will be ...
echo json_encode(
array(
'draw' => $_POST['draw'],
'data' => [],
'recordsFiltered' => 0,
'recordsTotal' => 0
)
);
In pure json
{"draw":1,"data":[],"recordsFiltered":0,"recordsTotal":0}
In short no matter what Datatable as on 2020 needs this parameters on server side handling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With