Server Side Processing and iDisplayStart

Server Side Processing and iDisplayStart

VirasViras Posts: 4Questions: 0Answers: 0
edited March 2010 in Bug reports
Hi!

I'm using the DataTables plugin with ServerSide Processing. This works perfectly fine, however as soon as I set the 'iDisplayStart' value on table initialization (using the 'iDisplayStart' option), it seems to get out of sync. The Pagination buttons show the correct page, but the GET variable passed to the server side script is always 0.

As soon as I click a pagination button, it works again. This only seems to happen for the first time call when a 'iDisplayStart' is passed to the constructor.

Any advice? I guess this is a bug :).

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I've just tried the following:

    [code]
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../examples_support/server_processing.php",
    "iDisplayStart": 10
    } );
    [/code]
    on this page: http://datatables.net/examples/data_sources/server_side.html - and it seems to work as expected. Are you using 1.6.2?

    Allan
  • donhofidonhofi Posts: 1Questions: 0Answers: 0
    I have this problem too.
    After debugging I found this place in the code which sets oSettings._iDisplayStart to 0. (function _fnFilterComplete)

    [code]/* Redraw the table */
    oSettings._iDisplayStart = 0;
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );[/code]

    If I replace it with this older part of code it works:

    [code]if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
    {
    oSettings._iDisplayStart = oSettings.iInitDisplayStart;
    oSettings.iInitDisplayStart = -1;
    }
    else
    {
    oSettings._iDisplayStart = 0;
    }
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    As I noted in my previous comment - the code I posted is working as expected. It jumps the display straight to the second page. Perhaps you could post a link to an example where this is not working so I can reproduce the issue?

    Allan
  • VirasViras Posts: 4Questions: 0Answers: 0
    Hi allan,

    Sorry for my delayed answer. Unfortunately I can't show you a live example of the datatables in action, as I don't have a place to host it yet.

    However here are the relevant parts:
    [code]dataTablesObj = $( "#vehiclesList" ).dataTable( {
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bFilter": false,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "index.php?module=list_dataTables",
    "fnDrawCallback": function() {
    $("a[rel^='prettyPhoto']").prettyPhoto( { theme: 'dark_rounded' } );
    },
    "aaSorting": [[2,"asc"]],
    "iDisplayLength": 10,
    "iDisplayStart": 20
    } );[/code]

    This shows the complete initialisation (actually I'm using dynamic values for iDisplayLength and iDisplayStart but to make sure that the error doesn't come from there, I used static values).

    Still the iDisplayStart value passed to the server-side-script is 0, all other values are set correctly.
  • VirasViras Posts: 4Questions: 0Answers: 0
    Actually here are two screenshots to show what I mean:

    http://img17.imageshack.us/img17/8199/paginationbuttons.jpg
    http://img717.imageshack.us/img717/8995/getoutput.jpg

    First one shows the pagination buttons, they display correctly. The second one shows a var_export of the $_GET array with the wrong value set to iDisplayStart!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Got it - thanks for the info Viras :-)

    Here is the fix. Replace the following code in _fnDraw:

    [code]
    /* If we are dealing with Ajax - do it here */
    if ( oSettings.oFeatures.bServerSide &&
    !_fnAjaxUpdate( oSettings ) )
    {
    return;
    }

    /* Check and see if we have an initial draw position from state saving */
    if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
    {
    oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
    0 : oSettings.iInitDisplayStart;
    oSettings.iInitDisplayStart = -1;
    _fnCalculateEnd( oSettings );
    }
    [/code]
    with:

    [code]
    /* Check and see if we have an initial draw position from state saving or initilaisation */
    if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
    {
    if ( oSettings.oFeatures.bServerSide )
    {
    oSettings._iDisplayStart = oSettings.iInitDisplayStart;
    }
    else
    {
    oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
    0 : oSettings.iInitDisplayStart;
    }
    oSettings.iInitDisplayStart = -1;
    _fnCalculateEnd( oSettings );
    }

    /* If we are dealing with Ajax - do it here */
    if ( oSettings.oFeatures.bServerSide &&
    !_fnAjaxUpdate( oSettings ) )
    {
    return;
    }
    [/code]
    I'll make sure this is in the next release of DataTables.

    Regards,
    Allan
  • VirasViras Posts: 4Questions: 0Answers: 0
    Works perfectly now, thanks a lot for fixing this!
  • MadLordMadLord Posts: 10Questions: 0Answers: 0
    edited March 2010
    Hi, Allan!
    First, sorry for my English...)))
    but this fix(7 post) don`t work for me....I have
    [code]
    "bServerSide": true,
    "sAjaxSource": "my.php",
    "fnServerData": fnXml2Json,
    "fnRowCallback": fnRow_ch,
    [/code]
    if i go to second page and click on button wich call oTable.fnDraw then table show me first page...but i need to stay on second...i use datatable 1.6.2...
  • MadLordMadLord Posts: 10Questions: 0Answers: 0
    up...problem still is....
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi MadLord,

    Try passing 'false' to fnDraw ( oTable.fnDraw( false ) for example). As the documentation says ( http://datatables.net/api#fnDraw ): bool (optional): indicate if the redraw should be complete (i.e. re-sort and re-filter), which has the side effect of resetting the pagination, or just update the display as it is. Default - true.

    Regards,
    Allan
  • MadLordMadLord Posts: 10Questions: 0Answers: 0
    no...not working...I think my problem same as here
    http://datatables.net/forums/comments.php?DiscussionID=1727&page=1#Item_0
    But can be more simple way, than specified there?
This discussion has been closed.