Sai Ram

Sai Ram

  • NA
  • 237
  • 112.8k

Jquery DataTable ReInitialize Not Working

Nov 16 2019 10:04 PM
Hi,
 
How to destroy and reinitialize the values for datatable. I am not able to achieve this...
 
HTML
  1. <select id='ddlstatus'  
  2. <option value='Inserted'>Inserted</option>  
  3. <option value='Approved'>Approved</option>  
  4. </select>  
  5.   
  6. <table id="example">  
  7. <thead>  
  8. <tr>  
  9. <th>OrderId</th>  
  10. <th>Order</th>  
  11. </tr>  
  12. </thead>  
  13. </table>  
JQuery
  1. var dtexample = 'undefined';  
  2. $(document).ready(function()  
  3. {  
  4. $("#ddlstatus").change(function()  
  5. {  
  6. loadDT();  
  7. event.preventDefault();  
  8. });  
  9. loadDT();  
  10. });  
  11. function loadDT()  
  12. {  
  13. var status = $("#ddlstatus).val();  
  14. if(dtexample != 'undefined' )  
  15. {  
  16. dtexample.destroy();  
  17. }  
  18. if(status == "Inserted" )  
  19. $("#example").append("<tbody><tr><td>1</td><td>ABC</td></tr></tbody>");  
  20. else  
  21. $("#example").append("<tbody><tr><td>2</td><td>DEF</td></tr></tbody>");  
  22. dtexample = $("#example).DataTable();  
  23. }  

Answers (1)