0

I want to stay on particular page after deleting the records in the datatable, but Ajax.reload() does not work here.

I have tried datatable ajax method.

<table class="table datatable-show-all" id="my-datatable">
<script type="text/javascript"                   
       src="~/Scripts/plugins/forms/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="~/Scripts/datatables_advanced.js"></script>

success: function(flag) {
        if (flag.flag === true) {
         alert("Successfully deleted !");
            $('#my-datatable').DataTable().ajax.reload(null, false);
          }
    }

When I Click the button it successfully deleted and reload the page if i use location.reload(). but I i want to reload the particular table in data table not The same page . I does not reload when i use above code.

Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
Talukder
  • 51
  • 2
  • 11
  • You can re render your data-table after successful deletion. – Sudhir Ojha Oct 31 '19 at 07:15
  • 1
    is the above success portion in an ajax request function? – Icewine Oct 31 '19 at 07:17
  • Please check here [https://stackoverflow.com/questions/18490026/refresh-reload-the-content-in-div-using-jquery-ajax](https://stackoverflow.com/questions/18490026/refresh-reload-the-content-in-div-using-jquery-ajax) Thanks – Mohit Sidoliya Oct 31 '19 at 08:52
  • Yes, it is. and it also succefully deleted and go to the first page if i use location.reload.But i want stay same page after load.@Icewine – Talukder Oct 31 '19 at 10:01
  • @MohitSidoliya i have followed following link u provided but it load the whole page does not reload on particular page – Talukder Oct 31 '19 at 10:10

1 Answers1

0

@talukder I have tried this and this was working fine. But if this is not working for you then you can remove that row by using jquery remove() method when you click on the delete button for deleting the record. You can reach that row by using jquery selector and code should be like that:

$(document).ready(function() {
    $(document).on('click','.a',function() {
        var $this = $(this);
        var url_for_delete_functionality = 'url';
        //ajax code
         $.ajax({
                type: 'POST',
                url: url_for_delete_functionality, 
                data: post_data,
                success: function(msg) {
                    $this.closest('tr').remove();
                }
            });


    })
})

Thanks

Mohit Sidoliya
  • 164
  • 1
  • 6