Datatables with Scroller and Server-side Processing with deferLoading still loads data on table init

Datatables with Scroller and Server-side Processing with deferLoading still loads data on table init

jbrichaujbrichau Posts: 2Questions: 1Answers: 0

Hi,

I am using Datatables 1.10.11 with Scroller 1.4.1 and loading the data via server-side processing. Since I want my users to only see rows when they explicitly enter a search query, I am trying to use the deferLoading option. This works fine except when I'm using Scroller. It seems that Scroller triggers a draw of the table on initialisation, which triggers a load of the data on the server.

I made a JsFiddle demonstrating the issue: https://jsfiddle.net/jbrichau/gdLr4vmp/
In the fiddle, you see that the table is immediately filled with data. However, it should only be filled when you hit the reload button.

I also started fiddling around in the Scroller source, and noticed how a call to fnMeasure on init triggers a draw of the table. Changing the code on this line: https://github.com/DataTables/Scroller/blob/master/js/dataTables.scroller.js#L590 to that.fnMeasure(false); fixed my problem. However, I'm unsure of this is the way to go or not.

thanks for any help
Johan

Answers

  • dtkujawskidtkujawski Posts: 3Questions: 1Answers: 0

    I am experiencing the same issue. Did you find anything else out about this?

  • jbrichaujbrichau Posts: 2Questions: 1Answers: 0

    I am using the changes I mentioned and they are working fine.
    Unfortunately, it's not being picked up in the main version. Understandably, the forum is full of requests.

  • matthew35matthew35 Posts: 3Questions: 1Answers: 1

    I fixed this issue. The following fix has scroller check if deferLoading is set before trying to redraw the table on initialization.

    1. Grab the debug version of the scroller extension.
    2. Go to the line where $(this.s.dt.nTable).one( 'init.dt', function () { is written.
    3. Change that .one() to the following code:
    // Measure immediately. Scroller will have been added using preInit, so
    // we can reliably do this here. We could potentially also measure on
    // init complete, which would be useful for cases where the data is Ajax
    // loaded and longer than a single line.
    $(this.s.dt.nTable).one( 'init.dt', function () {
        var initdraw = typeof that.s.dt.oInit.deferLoading === undefined;
        // console.log("deferLoading is " + typeof that.s.dt.oInit.deferLoading);
        that.fnMeasure(initdraw);
    } );
    
This discussion has been closed.