Basic ajax DataTable configuration help
Basic ajax DataTable configuration help
I'm trying to use DataTables with php and mysql. I have an ajax call that is pulling in data as such:
[
{
“id"3,
"ptid":"blah",
"last_name":"blah",
"first_name":"blah",
"priv_application":"E",
"priv_document":"E",
"priv_note":"E",
}
]
I'm configuring DataTables with the following:
$('#listing').DataTable( {
"paging": false,
"searching": false,
"select": true,
ajax: {
url: '{{ url("administration/admindata") }}',
dataSrc: ''
},
columns: [
{ title: "ID" },
{ title: "PtID" },
{ title: "Last Name" },
{ title: "First Name" },
{ title: "Application" },
{ title: "Documents" },
{ title: "Notes" }
]
});
And the HTML for the table is as follows:
<table id="listing" class="display" width="100%"></table>
However, it doesn't want to load the data even though this configuration is exactly like the first example given here: https://datatables.net/manual/ajax
I'm getting the following error:
DataTables warning: table id=new-search-members-listing1 - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
Any assistance is greatly appreciated.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
You need to use
columns.data
to tell DataTables where to get the data from (notcolumns.title
- although you probably want that as well). See this part of the documentation page you linked to.So for example you might have:
(showing just one of them - the others would be similar of course).
Allan
Perfect just missed that. Thanks!