Using AJAX sourced data with DataTables 1.10.3
Using AJAX sourced data with DataTables 1.10.3
Hi,
I'm switching from 1.9.4 to 1.10.3 and I'm having an issue with AJAX sourced data.
My backend is based on Java, particularly Spring MVC which returns data formatted in JSON.
@RequestMapping(value = "/persons")
public @ResponseBody List<Person> findAll() {
return personService.findAll();
}
Here is my DataTables' configuration:
var oTable_myTableId;
var oTable_myTableId_params = {
"initComplete": function(oSettings, json) {
oTable_myTableId.columns.adjust().draw();
},
"ajax": "\/context\/persons",
"columns": [{
"defaultContent": "",
"data": "id"
}, {
"defaultContent": "",
"data": "firstName"
}, {
"defaultContent": "",
"data": "lastName"
}, {
"defaultContent": "",
"data": "address.town.name"
}, {
"defaultContent": "",
"data": "mail"
}],
"deferRender": true
};
$(document).ready(function() {
oTable_myTableId = $('#myTableId').dataTable(oTable_myTableId_params);
});
However, it always fails on the following line:
for ( var j=0, jen=tds.length ; j<jen ; j++ ) {
cellProcess( tds[j] );
}
with the error: Cannot read property length of undefined
.
Moreover, no XHR request is fired.
Did I miss something to tell DataTables that data come from an AJAX source?
EDIT: I've also tried with the following parameters:
"ajax": {
"url": "\/context\/persons"
"dataSrc": "",
}
Same result unfortunately :-/
Thanks!
Regards,
Thibault.
Answers
Does somebody have any idea? :-/
Hello Thib. Just wondering if you ever found a way to resolve this? If so, would greatly appreciate it if you could share details of your resolution, as I'm coming across the same issue and am finding it terribly difficult to sort this out. Thanks so much.
Sorry I didn't see this thread at the time. I would need a link to a page showing the issue, or a debugger trace please.
Thanks,
Allan
Hi Allan. See my last comment in another thread:
http://datatables.net/forums/discussion/22585/ie-7-8-and-fngetrowelements-fail
as my inquiry in both threads concerns the same central issue of "tds" being undefined upon switching to 1.10.5 from 1.9.0.
Thanks.
Hello Thib, thought you may be interested in knowing that Allan had helped me resolve my issue which looks to be the similar if not the same as yours.
As Allan explained to me:
"The issue is that when you initialise the DataTable there is an empty <tr> element in the <tbody> (e.g. you have <tbody><tr></tr></tbody>).
Just remove that empty <tr> to resolve the issue.
The reason for this being an error is that DataTables expects there to be a cell for every column in each row. Anything else is an error condition."