DataTable not showing the data

DataTable not showing the data

mcvrmcvr Posts: 4Questions: 2Answers: 0

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    In my experience the cannot read property 'length' of undefined error means that the number of columns defined in the table don't match the number defined in Datatables. You have two columns in Datatables. I might be missing it but I don't see your table config in HTML. How many columns do you have defined?

    Kevin

  • mcvrmcvr Posts: 4Questions: 2Answers: 0
    edited April 2017

    Please find my HTML of the table.

    Do you think can it be a problem with my JSON ?

    <table class="display jqueryDataTable" id="example"> <thead> <tr> <th>ID</th> <th>Description</th> </tr> </thead> <tbody> </tbody> </table>

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    By default datatables looks for the 'data' element in the json. It can't find it, therefore it's 'undefined'. DataTables provides a way to specify the element to use. Comparing your json with that on the documentation link below you should be able to specify ajax.dataSrc = "jsonData" or change "jsonData" to "data" in your data object. I would recommend switching to the new naming convention for the datatable options if possible, it's more clear and the documentation is tailored towards it. If you can't use the new naming scheme changing your json object is probably the best option.

    Documentation: https://datatables.net/examples/ajax/custom_data_property.html

This discussion has been closed.