Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82395

How to navigate to previous page when removing the last element of any other page

$
0
0

Hi.
We have a server-side datatable loaded with ajax requests. We have one button to add a row (which refreshes the datatable accordingly) and another button in each row to remove it.
When we remove the element we call the following function:

    $.ajax({
        dataType: 'json',
        contentType: "application/json;charset=UTF-8",
        type: 'POST',
        url: 'ajaxDelete.json?itemId='+id
    }).done(function(data, textStatus, jqXHR) {
        if(data.status == "200") {
            $("#elementTable").DataTable().draw(false);
            $(".sucessDelete").show();
        } 
    });

The problem comes when the removed element is the last one on that page. The table is redrawn and it remains on the same page (because of the false argument when calling to the draw function). As it was the last one, the page is empty and the bottom info says "Showing elements from 11 to 10 of 10". We'd like the table to automatically navigate to the previous page.
We've tried to use draw() (with the default true), but this makes the datatables to navigate always to the first page, and we don't want that when it's not necessary.

What should we do?


Viewing all articles
Browse latest Browse all 82395

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>