fnGetAdjacentTr and serverside processing

fnGetAdjacentTr and serverside processing

sqtsqt Posts: 9Questions: 0Answers: 0
edited August 2012 in Plug-ins
I'm using the fnGetAdjacentTr and Serverside data. I can get next/previous records for any row on screen, but when I have a table of more then one page (pagination = full_numbers), it stops.

Is there a way to trigger loading the next/previous page, so fnGetAdjacentTr can continue fetching data?

Replies

  • sqtsqt Posts: 9Questions: 0Answers: 0
    I've done some work on the fnGetAdjacentTr function to make it switch pages when it reaches a boundary. (only previous atm)

    [code]
    $.fn.dataTableExt.oApi.fnGetAdjacentTr = function ( oSettings, nTr, bNext )
    {
    /* Find the node's position in the aoData store */
    var iCurrent = oSettings.oApi._fnNodeToDataIndex( oSettings, nTr );

    /* Convert that to a position in the display array */
    var iDisplayIndex = $.inArray( iCurrent, oSettings.aiDisplay );
    if ( iDisplayIndex == -1 )
    {
    /* Not in the current display */
    return null;
    }

    /* Move along the display array as needed */
    iDisplayIndex += (typeof bNext=='undefined' || bNext) ? 1 : -1;

    /* Check that it within bounds */
    if ( iDisplayIndex < 0 )
    {
    if (oSettings._iDisplayStart > 0 )
    {
    // we are not on page one, go the previous page
    oSettings.oApi._fnPageChange( oSettings, "previous" );
    // Refresh page to get data
    oSettings.oApi_.fnDraw(oSettings)
    // return last Tr of this page
    returnTR = oSettings.aoData[ oSettings.aiDisplay[ oSettings.aiDisplay.length-1 ] ].nTr;
    return returnTR;
    }
    else
    {
    // no previous record
    return null;
    }
    }
    else if ( iDisplayIndex >= oSettings.aiDisplay.length )
    {
    // TODO
    /* There is no next/previous element */
    return null;
    }

    /* Return the target node from the aoData store */
    return oSettings.aoData[ oSettings.aiDisplay[ iDisplayIndex ] ].nTr;
    };
    [/code]

    When testing, I get the correct pagechange, and in firebug I can see I get the correct returnTR;
    But within my javascript code, the returned TR is the last Tr of the page before switching! Any idea why the reference is swiching when returning??

    I can see the page swiching happening on screen, so that seems to work.
  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    When using server-side processing, the only TR elements that exist for the table are those shown in the body - that's the whole point of server-side processing, only the current body is visible and available.

    Sorry to say, but there is simply no way that fnGetAdjacentTr will ever work with server-side processing.

    Allan
  • sqtsqt Posts: 9Questions: 0Answers: 0
    I got it working already! I simply switch pages and return the iDisplayIndex number in stead of the Tr. From my own javascript, I fetch the Tr from that state and I get the correct one working.
    Time permissing,I'll make a demo for it this
This discussion has been closed.