I'm using DataTables 1.10.x and would like to populate the data in my table using JSON objects.
$(document).ready( function () {
$('#diagtable').dataTable( {
"ajax": '/api/v1/diag/1/',
"columns": [
{ "date": "date" },
{ "diagnosis": "diagnosis" }
],
dom: 'T<"clear">lfrtip',
} );
} );
I realize the { "date": "date" }, does not look right, but I'm unsure what else to use in between the first quotes.
My table goes below:
<table id="diagtable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Diagnosis</th>
<th> </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
My AJAX call returns the following JSON:
[
{
"date":"2010-03-20",
"diagnosis":"Test1"
},
{
"date":"2015-03-21",
"diagnosis":"Test2"
}
]
I see the proper AJAX call is made by DataTables (HTTP 200), but the table says "loading...".
I tried playing around with the below, but still no data gets populated in my table.
"aoColumns": [
{ "mData": "date" },
{ "mData": "diagnosis" }
]
The documentation shows to use:
"columns": [
{ "data": "name" },
...
But I don't have this "data" or similar in my JSON. I cannot change my JSONs either.
Any idea what I'm doing wrong?