DataTables - server side: "No matching records found" & "filtered from NaN total entries"
DataTables - server side: "No matching records found" & "filtered from NaN total entries"

Here is my client side code setting up the DataTable:
var apiUrl = '/companies.php?mode=list';
var table = $('#companiesTable').DataTable({
responsive: true,
serverSide: true,
ajax: {
dataType: 'text',
type: 'POST',
url: apiUrl,
dataSrc: function (json) {
return $.parseJSON(json);
}
},
columns: [
{
data: 'name',
responsivePriority: 1,
width: '30%',
render: function (data, type, row) {
return '<a href="/app/company.php?id=' + row.id + '">' + row.company_name + '</a>';
}
},
{
data: 'tel',
responsivePriority: 3,
width: '20%'
},
{
data: 'website',
responsivePriority: 4,
width: '15%',
render: function (data, type, row) {
return '<a target="_blank" href="' + row.website + '" class="trunc">' + truncate(row.website, 16) + '</a>';
}
},
{
data: 'id',
orderable: false,
responsivePriority: 2,
width: '15%',
render: function (data, type, row) {
var url = '/contact.php?id=' + row.id;
return '<a href="' + url + '" class="btn btn-sm btn-secondary">View</a> '
<?php if ($activeUser->can('delete')) { ?>
+ '<a href="#" class="btn btn-sm btn-secondary delete-person" data-person="' + row.name + '" data-id="' + row.id + '">Delete</a>'
<?php } ?>
;
}
}
]
});
```````````
Here is the returned JSON:
{
"sql": "SELECT * FROM companies WHERE deleted_at IS NULL AND 1 ORDER BY id asc LIMIT 10 OFFSET 0",
"draw": 1,
"recordsTotal": "1426",
"recordsFiltered": "1426",
"data": [
{
"id": "2",
"company_name": "aaaaa",
"tel": "00000",
"website": "",
"notes": "",
"created_at": "2020-01-31 11:32:03",
"updated_at": "2020-01-31 11:32:03",
"deleted_at": null,
"DT_RowId": "row_0",
"DT_RowData": {
"pkey": 0
}
},
{
"id": "3",
"company_name": "aaaaa",
"tel": "00000",
"website": "",
"notes": "",
"created_at": "2020-01-31 11:32:03",
"updated_at": "2020-01-31 11:32:03",
"deleted_at": null,
"DT_RowId": "row_1",
"DT_RowData": {
"pkey": 1
}
},
{
"id": "4",
"company_name": "aaaaa",
"tel": "00000",
"website": "",
"notes": "",
"created_at": "2020-01-31 11:32:03",
"updated_at": "2020-01-31 11:32:03",
"deleted_at": null,
"DT_RowId": "row_2",
"DT_RowData": {
"pkey": 2
}
},
{
"id": "5",
"company_name": "aaaaa",
"tel": "00000",
"website": "",
"notes": "",
"created_at": "2020-01-31 11:32:03",
"updated_at": "2020-01-31 11:32:03",
"deleted_at": null,
"DT_RowId": "row_3",
"DT_RowData": {
"pkey": 3
}
}, // ..... etc, etc, etc
]
}
`````
And my result is: "No matching records found", and I also get: "Showing 0 to 0 of 0 entries (filtered from NaN total entries)"
Can anyone explain where I am going wrong?
This discussion has been closed.
Answers
One thing, it looks your first field is
name
, but there isn't a name element in the returned JSON.Colin