I am using jQuery DataTables and looking for a way how to generate DataTable fully from JSON. This should include the number of columns, their names, row data, but also may include other settings like sorting. I've seen this is possible, but among the many possible approaches not many work for me.
Here is my code, can you help me fix the error and elaborate on my current JSON config?
JSON - put here as much as possible:
{
"columns": [
[ "title" : "DT_RowId" ],
[ "title" : "supplier" ],
[ "title" : "color" ],
],
"data": [
[ "row_3", "small", "red" ],
[ "row_3", "medium", "blue" ],
[ "row_3", "medium", "blue" ],
[ "row_11", "large", "blue" ],
]
}
JS:
$('#example').DataTable( {
"ajax" : {
"url": "http://127.0.0.1/tabledata.json",
"type": "GET",
"contentType" : "application/json",
"dataType" : "jsonp",
},
});
HTML - should be left to minimum:
<table id="example"></table>
Current error:
TypeError: undefined is not an object (evaluating 'e[i].aDataSort')
contentType: "application/json", dataType: "jsonp"
to be attached to the HTTP request headers. I can't see where it could be attached to your dataTable initialization script. Probably I need a variant that uses$.ajax()
call. – Fiacre