No matching records found even though the json result is sent and push via dataSrc function
No matching records found even though the json result is sent and push via dataSrc function

I have below my datatable codes.
$('#dashboard').DataTable({
"order": [[ 1, "asc" ]],
"aoColumnDefs" : [
{
'bSortable' : false,
'aTargets' : [ 0,2 ]
}],
"processing": true,
"serverSide": true,
"destroy":true,
"ajax": {
"url" : "dashboard.php",
"type": "POST",
"dataType": 'json',
"cache": false,
"data" : {
"checkAll" : "1",
},
/*success: function(results) {
//should create datatable from data
},*/
"dataSrc" : function (results) {
console.log("json length "+results["data1"]);
console.log("json value is "+JSON.stringify((results.data1)));
return results.data1;
},
error: function(error) {
$('#result').html(error);
}
},
//dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
}
);
The problem it keep showing me no matching records found. I am passing from php via this way echo json_encode(array("data1" =>$json_data));
and when I check the return results is something like this.
data1: {draw: 1, recordsTotal: 3, recordsFiltered: 3,…}
What else could be wrong cause the datatype also I have set as json ?
This discussion has been closed.
Answers
Hi @newbie14 ,
You've enabled
serverSide
, so the server is responsible for doing all searches. The protocol is discussed here. It would be worth checking your browser's network tab to ensure the server is returning the data in the expected format.Cheers,
Colin
Hi Colin,
Yes I can see the in my browser's network tab there is data here its
data1: {draw: 1, recordsTotal: 3, recordsFiltered: 3,…}
. Off course its much longer but I keep it simple this the data I got back from the server. There is 3 recordsTotal etc.So, the data is being returned, but nothing is showing in the table? Are you able to link to your page?
Cheers,
Colin
Hi Colin,
Yes I am able to link to my page. Previously I was able to send like this format. Like the below codes.
And the return from php is like this
echo json_encode($json_data);
. This settings works fine. The problem now I want to return 2 different array from phpecho json_encode(array("data1" =>$json_data,"data2" =>$data2Array));
. So this the problem is just single array my grid works perfectly fine.