Skip to content
Loading
Refresh DataTable after Add
 Now for every Action, you can reload the dataTable on Success function with
 
 
  1. $('#dataTable').DataTable().ajax.reload();      
 for example for delete
  1. $('#tblLocation').on('click', '.btnDelete', function (e) {    
  2.         debugger;    
  3.          e.preventDefault();  
  4.         var Id = $(this).attr("data-Id");    
  5.         $.ajax({    
  6.     
  7.             type: "Post",    
  8.             url: "/Admin/DeletePost",    
  9.             dataType: "html",    
  10.               
  11.             data: { Id: Id },    
  12.     
  13.             cache: false,    
  14.             success: function (res) {    
  15.                 debugger;    
  16.                 $('#dataTable').DataTable().ajax.reload();    
  17.                  
  18.                 alert("Deleted successfully");    
  19.     
  20.             }    
  21.         })    
  22.     
  23.           
  24.     });  
 similarly for add and Update.
+1
  • Hi
     
      How can i refresh according to my code. With ref to your code i get data in datatable but Searching,Show entries functionality not working, I am not able to trace that issue
     
    Thanks 
    0
  • Jignesh Kumar
    Hi,
     
    Please refer this link which will help you out, You need to call Get method to bind table after record inserted in database.
     
    https://www.c-sharpcorner.com/blogs/how-to-insert-and-retrieve-data-using-jquery-ajax-in-asp-net 
    0