DataTable not showing the data
DataTable not showing the data
mcvr
Posts: 4Questions: 2Answers: 0
Hello,
I am cracking my head to find a solution to this problem.
This discussion has been closed.
Answers
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
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>
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