FixedColumns performs four identical server requests on creation
FixedColumns performs four identical server requests on creation
Using a serverside table with two fixed columns, the table performs four identical requests to the server before rendering the first page of the table. See here the network protocol:
https://docs.google.com/file/d/0B-C44vw27ypxS1kwQ1RlVnFpWk0/edit?usp=sharing
And here is my jsfiddle to reproduce it:
http://jsfiddle.net/rplantiko/yKYCA/show/
This is the code for initialization. The first request is the "normal" one, from the datatable initialization. The successive three requests stem from the initialization code of FixedColumns:
var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://datatables.net/release-datatables/examples/server_side/scripts/jsonp.php",
"aoColumns": [
{"sWidth": "250px"},
{"sWidth": "200px"},
{"sWidth": "200px"},
{"sWidth": "200px"},
{"sWidth": "200px"}
],
"sScrollX":"100%",
"sScrollXInner":"110%",
"bScrollCollapse": true,
"fnServerData": function(sUrl, aoData, fnCallback) {
$.ajax({
"url": sUrl,
"data": aoData,
"success": fnCallback,
"dataType": "jsonp",
"cache": false
});
}
});
new FixedColumns( oTable, { iLeftColumns: 2 } );
The formula for the total number of identical requests is:
#identicalrequests = 2 + iLeftColumns
Kind regards,
Rüdiger
https://docs.google.com/file/d/0B-C44vw27ypxS1kwQ1RlVnFpWk0/edit?usp=sharing
And here is my jsfiddle to reproduce it:
http://jsfiddle.net/rplantiko/yKYCA/show/
This is the code for initialization. The first request is the "normal" one, from the datatable initialization. The successive three requests stem from the initialization code of FixedColumns:
var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://datatables.net/release-datatables/examples/server_side/scripts/jsonp.php",
"aoColumns": [
{"sWidth": "250px"},
{"sWidth": "200px"},
{"sWidth": "200px"},
{"sWidth": "200px"},
{"sWidth": "200px"}
],
"sScrollX":"100%",
"sScrollXInner":"110%",
"bScrollCollapse": true,
"fnServerData": function(sUrl, aoData, fnCallback) {
$.ajax({
"url": sUrl,
"data": aoData,
"success": fnCallback,
"dataType": "jsonp",
"cache": false
});
}
});
new FixedColumns( oTable, { iLeftColumns: 2 } );
The formula for the total number of identical requests is:
#identicalrequests = 2 + iLeftColumns
Kind regards,
Rüdiger
This discussion has been closed.
Replies
Allan
you are right, the redundant requests disappear when I use the nightly build. I have made another version of the jsfiddle, using the nightly version, which performs only one server request.
http://jsfiddle.net/rplantiko/yKYCA/7/
The base version (no version number) still is using the "stable" release.
So I consider this problem fixed with your new development. Is it wise to use that "nightly" version in a development project?
Regards,
Rüdiger
nightly: http://jsfiddle.net/rplantiko/yKYCA/7/
stable: http://jsfiddle.net/rplantiko/yKYCA/
Regards,
Rüdiger
The new base version of my jsfiddle contains a solution:
http://jsfiddle.net/rplantiko/yKYCA/
In fnServerData, I reuse results of previous requests if the request data were identical. To keep the requests asynchronous, a queue of callbacks is maintained and is processed when the Ajax returns.
As you see, there is only one jsonp.php request when the table is initialized. All successive identical requests will be provided with (almost) identical response data.
The only difference in the requests is sEcho - which has to be mangled into the buffered response data.
Regards,
Rüdiger
This method does something similar: http://datatables.net/release-datatables/examples/server_side/pipeline.html
Allan
thanks for your feedback! Yes, the pipeline looks similar (but doesn't solve my problem at hand).
I have no ressource problems with my database table, the serverside response time on a paging event is around 30ms + 1.2 * #displayRows (10, by default) and won't get much worse on production (at least that's what I expect).
With my solution, I am left with one small problem: I need to execute some final things on the page *after* the last of the (2 + iLeftColumns) identical request has been finished. Currently, the same callback is performed N times, but I think the first (1+iLeftColumns) only need to perform the standard fnDrawCallback.
This is no more a problem than it is slightly inefficient: Why instruct the browser to call the onSuccess function more often than needed. But it's bothering me.
My own callback has to be done only once: when everything is finished, i.e. when the callback of the (2+iLeftColumns)st request has been done. How could I register my function for that moment?
Regards,
Rüdiger