Can't get data to display in table when using ajax call.
Can't get data to display in table when using ajax call.
Hello, I am stumped by this. I am trying to switch some old datatables code over to an ajax call and even though I know I am getting data back, it just keeps saying no data available in table.
here is the code:
$.when(lr.getNeedsReviewLabs(facID, provID, memberID, sDate, eDate, provRev, patRev, abOnly, provSpecific)).done(function (resultsList) {
$('#tbl1').dataTable({
"data": resultsList,
"ajax.dataSrc": "",
"columns":[
{"data":"resultDate"},
{"data":"description"},
{"data":"patientName"},
{"data":"dateOfBirth"},
{"data":"provider"},
{"data":"abnormal"},
{"data":"provider"},
{"data":"clinic"}
]
});
here is a sample of the data:
[
{
"abnormal": "Abnormal",
"clinic": "",
"dateOfBirth": "01/01/1988",
"description": "",
"patientName": "Bill Test",
"provider": "Peters, Mark",
"resultDate": "04/20/2017",
"reviewDate": "01/01/0001"
}
]
and the HTML:
<table id="tbl1" class="dataTable">
<thead>
<tr>
<th>Received</th>
<th>Description</th>
<th>Patient Name</th>
<th>DOB</th>
<th>Clin. Review</th>
<th>Abnormal</th>
<th>Provider</th>
<th>Clinic ID</th>
</tr>
</thead>
</table>
Using Fiddler, I can see the ajax call being made and the data coming back, but nothing displays. I have tried changing the setup a bunch of different ways, but have had zero luck. Any tips or suggestions would be greatly appreciated. Thanks!
Answers
I believe this line:
Should be:
Take a look at the examples here:
https://datatables.net/reference/option/ajax.dataSrc#Examples
Kevin
It should be normally, but the
ajax
option isn't actually being used in the above example. DataTables isn't making the Ajax call, it is being provided to DataTables via thedata
option in theresultsList
option.The above looks like it should work to me, although you have to have
resultsList
defined somewhere of course.Can you show the full code or even better, a link to the page?
Allan