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

Customizing SharePoint list and implementing Quick search using jQuery

Enable and Disable Client side People Picker using jQuery

How to generate PDF using jsPDF and html2canvas library