I’m trying (and failing) to load a jQuery DataTable using the built-in ajax source argument. The datatable, however, shows the message “Loading…” where the row(s) should be appearing.
Here’s my datatable call :
$('#my-table').dataTable(
{bFilter: false,
bInfo: false,
bJQueryUI: true,
bPaginate: false,
bStateSave: false,
bSort: false,
aoColumns: [ {"sTitle" : "Date"},
{"sTitle" : "Our Co."},
{"sTitle" : "Their Co."},
{"sTitle" : "Note"} ],
sAjaxSource: "/contact/company_name/"} );
Using Chrome, I can see that the call to /contact/company_name/ is occurring, is returning status 200, and has the following data: [[[Hello], [Goodbye], [Test1], [Test2]]] (which is my test data).
I can also see that the dataTables.min.js is returning the error Uncaught TypeError: Cannot read property 'length' of undefined.
I assume that my returned data is not formatted properly. Can anyone suggest the solution?
according to the website
your service should return data in this format:
so, wrap your array in an object, name the array as
aaDataand try again.or you can name it any way you like, but then you need to add the
sAjaxDataPropparameter in the datatables initialisation (say you name itdatayou would do it like this: