Bilal khan
Bilal khan

Reputation: 1

pagination jquery datatable after delete

After record delete from datatable, pagination is not updating.

for refresh datatable I am using this and it is working fine but not refreshing pagination. $('#mytable').load(location.href + " #mytable")

Upvotes: 0

Views: 498

Answers (1)

Negi Rox
Negi Rox

Reputation: 3922

As Per documentation row().remove() method which deletes a row from a table, and the draw() method with false as its first parameter. This will redraw the table keeping the current paging (without the false parameter the paging would be reset to the first page).

You can do something like the below no need to refresh it.

$(document).ready(function() {
    var table = $('#example').DataTable();// Store your refrence

    $('#example tbody').on( 'click', 'tr', function () {
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    } );

    $('#removeBtn').click( function () {

     $.ajax({
       url: "deletefile.aspx", 
       success : function(data){
          //delete the row
          table.row('.selected').remove().draw( false );
        },
       error: function(xhr){
           console.log(xhr);
        }}); 

    } );
} );

you can see the documentation here.

Upvotes: 1

Related Questions