DataTables callbacks and infinite requests
DataTables callbacks and infinite requests
blondeheron
Posts: 4Questions: 0Answers: 0
Hi all,
I'm experiencing the same problem described in this old discussion: http://datatables.net/forums/discussion/2259/fnserverdata-makes-infinite-http-request-when-we-have-the-callback-function/p1.
I'm using (as also described in the old discussion):
- server side processing
- sAjaxSource
- fnServerData
- $.ajax() calls in fnServerData, calling REST services
- callback function.
DataTables version is 1.9.4.
I'm experiencing the same problem described in this old discussion: http://datatables.net/forums/discussion/2259/fnserverdata-makes-infinite-http-request-when-we-have-the-callback-function/p1.
I'm using (as also described in the old discussion):
- server side processing
- sAjaxSource
- fnServerData
- $.ajax() calls in fnServerData, calling REST services
- callback function.
DataTables version is 1.9.4.
This discussion has been closed.
Replies
Allan
[code]buildTableDataAsync(data, fnCallback);[/code] is:
[code]
function buildTableDataAsync(json, callback) {
var credentials = json.aaData;
var buildPromises = [];
$.each(credentials, function(i, entry) {
buildPromises.push(buildRow(entry));
});
$.when.apply(null, buildPromises).always(function() {
aTable.fnClearTable();
aTable.fnAddData(rows);
if (callback) callback(json);
});
}
[/code]
In my intention:
1) the table loads partial table data via REST JSON service.
2) the buildTableDataAsync function makes two ajax calls (other rest services) per table row, composes the whole dataset and updates the table.
Unfortunately, using [code]fnClearTable[/code] or [code]fnAddData[/code] creates the infinite loop. So I'm doing something wrong.
I read using methods like [code]fnClearTable[/code] or [code]fnAddData[/code] using server-side processing could be bad, but this seemed to be the only viable way. I hope there's another solution...
Will do a redraw. As will fnClearTable. Hence the problem.
I'd suggest you manipulate the data as needed and then use the provide callback method.
Allan
Manipulating the data, in my table, involves calling buildTableDataAsync. Maybe have I to manipulate the data before invoking datatables?
It does if you have server-side processing enabled since there is no data 'held' at the client. It's really just a dumb viewer and event manger. Every draw, with server-side processing enabled, must call the server.
> Manipulating the data, in my table, involves calling buildTableDataAsync. Maybe have I to manipulate the data before invoking data tables?
If you are using server-side processing you need to manipulate it on every load. What is the manipulation you are going. You can bash the JSON around anyway you want and pass it into the callback in fnServerData :-)
Allan