fnReloadAjax causing "Uncaught TypeError: Cannot read property 'length' of undefined"
fnReloadAjax causing "Uncaught TypeError: Cannot read property 'length' of undefined"
mithun_daa
Posts: 11Questions: 0Answers: 0
I am trying to populate a datatable using a Ajax source everytime the user clicks a link. The URL gets generated upon clicking the link and when i call fnReloadAjax after that i get the above error. Looking at the network tab in Chrome Dev Tools, i see that the data is coming back from the server. The weirdest thing is that it works the first time and never works after that. Any help would be appreciated. Using datatables 1.8:
HTML:
[code]
SourceTargetCreatedAvgMinMaxIntervalEvents
[/code]
JS:
[code]
var latDT = $('#latDT').dataTable({ "bInfo": false,
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"sAjaxDataProp": "",
"sAjaxSource": '/Dashboard/GetServerLatencyInfo/?server=' + server,
"aoColumns": [
{ "mDataProp": "source" },
{ "mDataProp": "target" },
{ "mDataProp": "create" },
{ "mDataProp": "avg" },
{ "mDataProp": "min" },
{ "mDataProp": "max" },
{ "mDataProp": "interval" },
{ "mDataProp": "events" }
]
}); [/code]
[code]
$('.latLink').live('click', function () {
server = $(this).data('server');
//ldlg.dialog('open');
latDT.fnReloadAjax('/Dashboard/GetServerLatencyInfo/?server=' + server);
});[/code]
HTML:
[code]
SourceTargetCreatedAvgMinMaxIntervalEvents
[/code]
JS:
[code]
var latDT = $('#latDT').dataTable({ "bInfo": false,
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"sAjaxDataProp": "",
"sAjaxSource": '/Dashboard/GetServerLatencyInfo/?server=' + server,
"aoColumns": [
{ "mDataProp": "source" },
{ "mDataProp": "target" },
{ "mDataProp": "create" },
{ "mDataProp": "avg" },
{ "mDataProp": "min" },
{ "mDataProp": "max" },
{ "mDataProp": "interval" },
{ "mDataProp": "events" }
]
}); [/code]
[code]
$('.latLink').live('click', function () {
server = $(this).data('server');
//ldlg.dialog('open');
latDT.fnReloadAjax('/Dashboard/GetServerLatencyInfo/?server=' + server);
});[/code]
This discussion has been closed.
Replies
I have my [code]"sAjaxDataProp": ""[/code] and the fnReloadAjax extension was looking for data within [code]aaData[/code] All i had to do was delete it.
BEFORE:
[code]
/* Got the data - add it to the table */
for (var i = 0; i < json.aaData.length; i++) {
that.oApi._fnAddData(oSettings, json.aaData[i]);
}
[/code]
AFTER:
[code]
/* Got the data - add it to the table */
for (var i = 0; i < json.length; i++) {
that.oApi._fnAddData(oSettings, json[i]);
}
[/code]
Thanks for flagging this up! DataTables 1.8 now has an internal function called "_fnGetObjectDataFn" which is used to deal with this kind of thing, and the fnReloadAjax plug-in should also use it to make it match the behaviour of the main library. I've just updated the plug-in to do exactly that :-)
Allan