Help with server side array of objects
Help with server side array of objects
I am trying to get Datatables up and running and having a heck of a time. Here is the JSON from my server-side call:
{"errors":{},"success":true,"object":[{"id":1,"name":"Legal","externalSystemId":0},{"id":4,"name":"Customer Support","externalSystemId":0},{"id":8,"name":"New Accounts","externalSystemId":0}]}
I am just trying the name and ID to display in a table:
<table id="folders" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</tfoot>
</table>
And here is the javascript:
$('#folders').dataTable( {
processing: true,
serverSide: true,
ajax: {
url: 'folder/getProgramList/' + 3,
type: 'GET',
dataSrc: 'object',
columns: [
{ "data": "name" },
{ "data": "id" }
]
}
});
I get an error stating:
DataTables warning: table id=folders - Requested unknown parameter '0' for row 0.
From what I have read this should be limited to array types, not objects.
Any thoughts??
Thanks,
Steve
This question has an accepted answers - jump to answer
Answers
I'm just starting myself, so I may be wrong, but try defining your columns in the root object passed to datatable:
Thanks. That did the trick!