stop pagination event in 1.9.4

stop pagination event in 1.9.4

pbercepberce Posts: 15Questions: 2Answers: 0
edited January 2020 in Free community support

Currently using DataTables v1.9.4 as I've been able to figure out how to do complex server side table joins for server side processing so I do not want to update to DataTables 1.10 at this time.

The DataTable I am trying to create uses server side processing. The table contains input elements that allows users to edit values. They have the option to "save" all editable values on the current page. If the user tries to change the page without saving all edits will be lost. So, if someone tries to change the page and there are edits present I want to stop the page change process and give them a yes/no type question to continue. If they select the "yes" option, the page change process continues, if they choose the "no" question then the page change process is terminated, which will then allow them to save

I know that you can create a custom event to fire when the page changes using:

$('#table_id').on('page', function () {
        // do something here
});

My question is, is there a way to stop the pagination process from happening during this event?

The only other thing I can think of doing is to automatically save during the page change process. I'd rather not do that, but, that may be my only choice if there is no way to terminate the page change process using the page event.

Answers

  • pbercepberce Posts: 15Questions: 2Answers: 0
    edited January 2020

    Providing a partial answer for my own question. When I initialize my table I assign it to a variable

    var oTable = $('#table_id').dataTable( {
    ...
    

    I was poking around the table object and I found that if I can use .stopAuto() on the table variable and it stops the pagination process.

    $('#table_id').on('page', function () {
        if(!confirm('allow page to change?')){
            oTable.stopAuto()
        }
    });
    

    BUT, it doesn't completely solve the issue. If I use stopAuto, it appears to stop the process. But if I then try to paginate again and allow it to continue the pagination process jumps by 2 pages, instead of 1.

This discussion has been closed.