How to add a confirm prompt for page change?

How to add a confirm prompt for page change?

YorkYork Posts: 5Questions: 3Answers: 0

I added a confirm prompt for page change, by using the page.dt event (https://datatables.net/reference/event/page).

How can I cancel the page change when the confirm prompt returns false?

JS Fiddle: http://jsfiddle.net/ebRXw/80/

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,848Questions: 1Answers: 10,134 Site admin
    Answer ✓

    There is no option to cancel the paging (it isn't mentioned anywhere in the documentation because there is no option to do that). The page event is simply to inform you that the paging has changed after it has changed.

    You would need to create a custom paging plug-in if you wanted to be able to confirm the paging change.

    Allan

  • YorkYork Posts: 5Questions: 3Answers: 0
    edited January 2015

    Here is a trick to do so.

    Use option preDrawCallback to cancel a draw.
    Use page.dt and length.dt to reset the page/length controller value.

    js fiddle: http://jsfiddle.net/ktbf8day/18/

  • YorkYork Posts: 5Questions: 3Answers: 0

    A simplified version is here. http://jsfiddle.net/ktbf8day/19/.

    This version responses to all draw event, but not limited to specific ones. Just preDrawCallback is needed.

    A confirm prompt is useful to prevent user from losing data in edit mode.

This discussion has been closed.