Can't get data to display in table when using ajax call.

Can't get data to display in table when using ajax call.

mpetempete Posts: 1Questions: 1Answers: 0
edited May 2017 in Free community support

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

  • kthorngrenkthorngren Posts: 21,591Questions: 26Answers: 5,004

    I believe this line:

    "ajax.dataSrc": "",
    

    Should be:

    "dataSrc": "",
    

    Take a look at the examples here:
    https://datatables.net/reference/option/ajax.dataSrc#Examples

    Kevin

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    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 the data option in the resultsList 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

This discussion has been closed.