DataTables - server side custom Prev / Next buttons.

DataTables - server side custom Prev / Next buttons.

Tom_TTom_T Posts: 24Questions: 3Answers: 0

Hi,

I'm just starting to use DataTables server side with an backend LDAP database.
So far I've got the page loading and displaying the first xx entries based on the 'show entries drop down'

Currently the prev and next buttons appear to work with id but is there any way after first load my backend page can send what values should be used for prev and next ?

My LDAP database doesn't have id entries, so when I';ve done paging in PHP I've used the **cn ** value. What I'm hoping is the backend page can return $prev & $next and those values are then used by the Prev & Next buttons.

Is that possible ?

Thanks

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0

    Thanks for the reply. I'm not going to be able to create a test case as the LDAP server is running locally and is partially proprietary so I've no way to get this online.

    I'm only trying to work out how to get Prev & Next to change what they send to the backend script. Are there any examples on that ?

    Thanks

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    The parameters Datatables sends and expects to receive are documented here. You can use either the ajax.data option or -optino preXhr event to alter the parameters sent to the server. You can use wither the ajax.dataSrc or xhr event convert the received parameters to what server side processing supports.

    Kevin

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0

    Thanks, I'm trying to use ajax.data to send which button, prev or next was pressed.

    If I use drawCallback I can detect if the next button is pressed and set variable button to next

    drawCallback: function() {
    
        $('.paginate_button.next:not(.disabled)', this.api().table().container())          
            .on('click', function() {
            alert('next');
            button = 'next'
    
    });
    

    But that appears to be triggered once the table is redrawn, So I've tried the same code but using preDrawCallback but that doesn't seem to do anything, when Next is clicked the alert isn't shown.

    Is there any way to do this ?

    Thanks

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    The page number can be derived by dividing the start parameter by the length parameter that is sent to the server. You may need to add one. IS this what you are looking for?

    If not please provide more details of what you are trying to do.

    Kevin

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0
    edited November 2021

    Hi Kevin,

    I want to send to my back end script either button = next or ** button = prev** depending on which button was pressed.

    Thanks

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    If there are no other paging buttons, you could do something like this. It's detecting whether the requested page is going forward or backwards. If there are other paging buttons, you can't tell if a specific page was pressed, or the specific "next"/"prev" buttons.

    Otherwise, I suspect you'll need to develop your own pagination plug-in that stores the press for you,

    Colin

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0

    Hi Colin, that does exactly what I need for the Prev / Next buttons. Thanks.
    Is there any way to remove the page numbers and only have buttons First, Prev & Next ?

    Thanks again

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0

    Looks like using

        "pagingType": "full",
    

    Removes the numbers and added First, Previous, Next, Last
    I should be able to work with that.. Thanks :)

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0

    Hi Colin,

    The example seems to work showing the Next or Prev in the console, but nothing is passed to my server script. I was expecting to see last in the posted results, but I don't. Any ideas ? Thanks

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    The ajax.data docs show that the first parameter passed into the success function is the data being sent to the server and that it needs to be updated. In the example the data variable will need updated to send the paging direction, for example:
    http://live.datatables.net/xonixujo/70/edit

    Kevin

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    And to tweak Kevin's example here, you can change pagingType to simple to only show Next/Prev,

    Colin

  • Tom_TTom_T Posts: 24Questions: 3Answers: 0

    I have the paging numbers and data passing working.
    Thanks for the help

Sign In or Register to comment.