Shared Pagination Control

Shared Pagination Control

jammyjamsjammyjams Posts: 4Questions: 0Answers: 0
edited July 2011 in General
Is it possible to control two tables with one paginator. If so, could you please explain how to do this? Thanks in advance for your help.

Jamil

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    There isn't a built in method of doing that, but there are two ways of doing it off the top of my head:

    1. Make one of the tables a "master" and have a draw callback function on it (fnDrawCallback), which will change the pagination of the slave table to match whatever the paging of the master is.

    2. You could use the API method fnPageChange to build your own paging controls and control both tables from that.

    Allan
  • jammyjamsjammyjams Posts: 4Questions: 0Answers: 0
    edited July 2011
    Thanks Allan. I went with #1 and did something like this:

    [code]
    "fnDrawCallback": function( oSettings ) {

    if(oSettings.oFeatures.bPaginate) {
    tblASettings._iDisplayStart = oSettings._iDisplayStart;
    tblASettings._iDisplayEnd = oSettings._iDisplayEnd;
    tblATable.fnDraw( false );
    }

    if(oSettings.oFeatures.bLengthChange) {
    tblASettings._iDisplayLength = oSettings._iDisplayLength;
    tblASettings._iDisplayStart = oSettings._iDisplayStart;
    tblASettings._iDisplayEnd = oSettings._iDisplayEnd;
    tblATable.fnDraw( false );
    }
    },
    [/code]

    Seems to work fine. Is this how you would do it?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Looks good to me - nice one! Thanks for sharing your solution with us.

    The only thing I would say is that at the moment both pagination and length changing are enabled then the slave table will be drawn twice. You might want to combine the if statements for that case.

    Allan
  • jammyjamsjammyjams Posts: 4Questions: 0Answers: 0
    Thanks for the tip. I didn't have any problems with them separated but combined them anyways.

    I did notice an error when I changed the length menu to All. It erased the table and pagination but didn't throw any errors.

    Do you have any thoughts as to what's going on?

    Jamil
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You might need to add a condition for the case when _iDisplayLength === -1 (i.e. display all) and set _iDisplayStart = 0 and _iDisplayEnd to the number of records: fnRecordsDisplay()

    Allan
This discussion has been closed.