How to clear a data table on button click jQuery

 Clearing a data table on button click jQuery

In many of the scenarios we have to clear a datatable on an event as its previous data is no longer in use, to achieve this there might be many approaches. I have used below approach to clear a datatable on button click using jQuery.

Code - 

$("#submit").on("click", function(){ 

   if ($('#tblData tbody tr').length > 0)

                {

                        $('#tblData thead').remove();

                        $('#tblData tbody').empty();

                        $('#tblData').DataTable().destroy();                        

                }

});




Comments

Popular posts from this blog

How to Customize exported excel's cell background color in Datatables

Populate dropdown using jquery ajax in SharePoint

Customizing SharePoint list and implementing Quick search using jQuery