FixedColumns performs four identical server requests on creation

FixedColumns performs four identical server requests on creation

rplantikorplantiko Posts: 18Questions: 1Answers: 0
edited August 2013 in General
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

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Which versions are you using? If not the nightly of FixedColumns, could you try that please (I'm on my phone atm so not so easy to check!). However, yes, this is a good point - FixedColumns should try to use some kind of caching if possible. Its because FixedColumns requires a redraw or two.

    Allan
  • rplantikorplantiko Posts: 18Questions: 1Answers: 0
    Hi 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
  • rplantikorplantiko Posts: 18Questions: 1Answers: 0
    My last answer was too quick: I just saw that the nightly version has the disadvantage that the fixed columns are not fixed any more (which, after all, was the main purpose for using FixedHeader :-) ). You'll see the difference when toggling between the versions:

    nightly: http://jsfiddle.net/rplantiko/yKYCA/7/

    stable: http://jsfiddle.net/rplantiko/yKYCA/

    Regards,
    Rüdiger
  • rplantikorplantiko Posts: 18Questions: 1Answers: 0
    For all who might be interested:

    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
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Cunning - like it :-).

    This method does something similar: http://datatables.net/release-datatables/examples/server_side/pipeline.html

    Allan
  • rplantikorplantiko Posts: 18Questions: 1Answers: 0
    Hi 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
This discussion has been closed.