Using bStateSave with server side pipelining

Using bStateSave with server side pipelining

eyre.michaeleyre.michael Posts: 21Questions: 0Answers: 0
edited March 2011 in General
Hello,

I am trying to get bStateSave to work with my table that I am using pagination and server side processing with the pipelining plugin.

The problem that I am having is when the table is loaded again. If I change the number of records that appear on each page, when I come back to the table, it will display the correct number and also return the correct number of records. The problem starts when I navigate to a page after the first page. When I return to the table, the information displayed in the table matches what was on there before, but instead of being on say the 2nd page, it appears to be on the first page. If you click on the next icon, the data displayed does not change, but if you then click on the previous button, you get back to the first page with the first page of data.

Looking at the call when the table gets loaded again, the iDisplayStart is set to 100 (because the length was set to 100 and I was on the second page when I left the table).

What I would like to see is that when we return to table, the user has the same number of show entries selected and on the same page they were on when they left.

I have searched the forum, but I have not been able to find a solution to this.

Thanks

Mike

Replies

  • eyre.michaeleyre.michael Posts: 21Questions: 0Answers: 0
    I am wondering if anyone has any idea on this. After doing some more digging, it seems that the sInfo is not getting updated with the information from the cookie. When I look at the network call, the display starting point and the display length is correct, but when everything comes back, it does not appear that the sInfo value is updated correctly.

    Thanks
  • eyre.michaeleyre.michael Posts: 21Questions: 0Answers: 0
    I have been doing some searching through the forum and through the code and I have narrowed the problem down to the sInfo information.

    If the user navigates to a page, other than the first one, leaves the page and then comes back. The data in the grid is correct, but the sInfo line still says "Showing 1 of..." instead of say "Showing 26 of ...". Also, the page buttons are not enabled correctly. If the user is not on the first page, I would want to have the previous button enabled.

    There is definitely something going on in the code, but I have not been able to figure it out yet.

    Any help would be great.

    Thanks

    Mike
  • eyre.michaeleyre.michael Posts: 21Questions: 0Answers: 0
    So I have been doing some investigation on the code, and I believe I have found the source.

    I put several breakpoints in and saw that the sInfo was correct until the last draw. When the table initially loads, the data from the server is correct, the sInfo is correct, but the columns are not aligned correctly. In the next step, where the column widths are set, the sInfo text is still correct. Then the code calls the _fnReDraw function. Within this function, the _fnSort function is called.

    In this function, the following condition is present:
    [code]
    /* No sorting required if server-side or no sorting array */
    if ( !oSettings.oFeatures.bServerSide &&
    (oSettings.aaSorting.length !== 0 || oSettings.aaSortingFixed !== null) )
    {
    [/code]

    Notice the condition about bServerSide. If the table has server side processing enabled, it will not sort the data array.

    Also within this function, it calls the _fnFilterComplete function:
    (Starting at line #4456)
    [code]
    /* Copy the master data into the draw array and re-draw */
    if ( oSettings.oFeatures.bFilter )
    {
    /* _fnFilter() will redraw the table for us */
    _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
    }
    else
    {
    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    oSettings._iDisplayStart = 0; /* reset display back to page 0 */
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );
    }
    [/code]

    There is no condition for server side processing. When you look at the code in the _fnFilterComplete function, the value of oSettings._iDisplayStart is getting set to 0 (zero) on line #4082, which will eventually set the sInfo text back to 1, instead of the original value.

    I tried to put a condition on the calling of the _fnFilterComplete function, based on the value of server side variable, but then the table did not load.

    Some how, the iDisplayStart should not be reset back to 0 (zero) when server side processing is happening.

    Any ideas where in the code we can do this and it will not affect the other functionality?

    I am going to keep trying different places to make sure things still work on all of my other grids.

    Thanks

    Mike
  • eyre.michaeleyre.michael Posts: 21Questions: 0Answers: 0
    I was not able to find a place to put an if condition for checking if server side processing was occurring, so I decided to comment out line #4082:
    [code]
    oSettings._iDisplayStart = 0;
    [/code]

    After doing that, my display is correct and all of my other grids are working also. This is the only grid that has the state save enabled and also server side.

    Allen: I am not sure if commenting out this line will not affect something else. There are many other places in the code that the oSettings._iDisplayStart is set to 0 (zero), but I don't think that it needs to be done in the fnFilterComplete function.

    Let me know what you think. I am very interested in knowing if this is the proper solution.

    I love this software and will continue to keep using it.

    Thanks

    Mike
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Mike,

    Good monologue :-) I've just been experimenting a bit with my example to reproduce the issue, but it seems to be doing what I would expect. I've put up a temporary example here: http://datatables.net/examples/server_side/_pipeline.html . Regardless of how I change the state of the table and then reload the state is held - or have I missed a step?

    Allan
  • eyre.michaeleyre.michael Posts: 21Questions: 0Answers: 0
    I am no David Letterman, but I try. :-)

    I looked at your example and I took away some of the options that I had on my table and everything worked. I then started re-enabling some of the features and found that I was doing an extra fnDraw call . When I removed that call, everything worked fine. I had this in the fnInitComplete section.

    Thanks for taking the time to help me on this.

    Mike
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Ah - good find :-). No problem at all.

    Regards,
    Allan
This discussion has been closed.