Detect "Next", "Previous" button

Detect "Next", "Previous" button

jc0966jc0966 Posts: 9Questions: 2Answers: 0

I am using Datatables 1.10 with server-side pagination and pagingType "simple.
So only the "Next" and "Previous" pagination buttons are displayed.
How can I determine which of these buttons is clicked?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    When DataTables makes the request to the server, the information it sends will contain everything the server needs to know about what data to gather. You don't need to explicitly know which button was clicked on.

    Allan

  • jc0966jc0966 Posts: 9Questions: 2Answers: 0
    edited February 2016

    Hi Allan,
    I need to do some processing on the client side before sending the request to the server.
    So I need to know if the user clicked the "Next" or "Previous" button. The processing is different based on whether it was "Next" or "Previous".

    Effectively (in pseudo-code)

    If (Next-button-clicked) {
        do something
    } else if (Previous-button-clicked) {
        do-something-else
    }
    

    send-request-to-server

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    You could use the ajax.data option and check what the start property is (see the server-side documentation. That's really the only way to see what page of data the DataTable is going to request. You would need to store the previous value to check to see if the new start point is greater or less than the previous.

    Allan

  • jc0966jc0966 Posts: 9Questions: 2Answers: 0

    Yes, I was going down the path of storing the previous "start" and comparing it with current when I posted the question because I thought there might be a better way.

    This post can be closed.

    Thanks.

This discussion has been closed.