Servside Search - Result not correctly shown in Datatable
Servside Search - Result not correctly shown in Datatable
I have a system with Datatables and Serverside processing of the data delivery and search.
This running good.
My problem is: If I try some search strings, I got a error by showing Data in Datatables. My php script delivers the JSON String, but in the Datatable, nothing is shown. The Infofield of Datatable show "Showing 1 to 0 of 3 entries (filtered from 956 total entries)". I think here is a missmatch between the return amount and the datatable settings (maybe: iDisplayLength?).
This happens only with some search results. In some cases it works perfectly.
If the error happes, I have a result looks like: {"sEcho":2,"iTotalRecords":956,"iTotalDisplayRecords":3,"aaData": "VALIDJSONSTRING with the found 3 Results from Database"}
Can anyone give me a hint, which parameter I forget to return? Are there a missmatches between "iTotalRecords" and "iTotalDisplayRecords"?
My datatable settings:
var done_parameter = getUrlParameter('done');
$('#datatable_fullsize_stammdaten_V2').DataTable( {
"aLengthMenu": [[250, 500, 2000, -1], [250, 500, 2000, "Alle"]],
"iDisplayLength": 500,
"processing": true,
"bServerSide": true,
ajax: {
url: locationvar.pluginurl+'json/get_json_stammdaten.php?content=caseid&done='+done_parameter,
dataSrc: 'data',
},
scrollY: '60vh',
scrollCollapse: false,
paging: false,
scrollX: true,
stateSave: true,
columns: [
{ "data": 13},
{ "data": 1 },
{ "data": 2, className:"td_alignleft" },
{ "data": 3 },
{ "data": 4 },
{ "data": 5 },
{ "data": 6 },
{ "data": 7 },
{ "data": 8 },
{ "data": 9 },
],
"columnDefs": [
{
"targets": '_all',
"render": function ( data, type, full, meta ) {
return '<a href="?cdst=4&caseid='+full[0]+'">'+data+'</a>';
//return '<a href="?cdst=4&caseid='+full[0]+'>'+data+'</a>';
}
}],
fixedColumns: false,
autoWidth: true,
info: true,
order: [[ 1, "asc" ]],
});
Answers
I found the error:
in js:
deactivated: order: [[ 1, "asc" ]], to //order: [[ 1, "asc" ]],
In my PHP file:
In my search function I cutted all not necessaryfrom the return array. So the return array get rows like: 3, 7,22 -> but it is necessary to get rows like 1,2,3,4
I has to got a increment of rows by one.
Now I verfy the Issue: When I set "safeState: true" or "order: [[ 1, "asc" ]]," I got issues with the search engine. My php script delivers the expected results. But the Datatable didn't show this results. I compared the POST URLs, there are slightly differences in column[5][regex]. It is setted to true in one case and to false in the error case.