stateSave +serverSide pagination bug when page no longer has records

stateSave +serverSide pagination bug when page no longer has records

kjjdionkjjdion Posts: 2Questions: 1Answers: 0

Let's say there are a total of 3 pages and I am using stateSave and serverSide. I go to the last page, so datatables remembers my last page was 3. I then delete the only record on that page. I then go back to my datatable. The 3rd page is now gone from the pagination menu, and it is telling me "No matching records found".

I tried fixing this by using the API:

if (api.page() > 0 && api.rows({page: 'current'}).count() === 0) {
    // set page to previous
    api.page('previous');
    // call draw() so state saves
    api.draw();
    // reload the table
    api.ajax.reload();
}

This does not correct the issue. It bugs out and then I have to manually refresh the page to get it to jump back to page 1. Ideally I would like it to simple go back 1 page and then redraw the table/pagination.

How do I correct this?

Answers

  • kjjdionkjjdion Posts: 2Questions: 1Answers: 0
    edited November 2018

    This is the closest I've got to where I want it to be:

        if (api.page.info().page > 0 && api.rows({page: 'current'}).count() === 0) {
            api.page('previous').state.save();
            location.reload();
        }
    

    How can I do this without reloading the entire page? Using api.ajax.reload() does not work either.

This discussion has been closed.