How to make invisible datatable when there is no data?

0
718

Despite good suggestions I think there still needs (another) answer.

  1. Using dataTables a <table> will never be empty – or :empty – since dataTables enforces you to have a <thead> and a <tbody>
  2. It is not enough to hide the <table>, you must hide the *_wrappper also – the <div> that contains the styled table, pagination, filter-box and so on.

You can take advantage of fnInitComplete :

$('#table').dataTable({
   //initialization params as usual
   fnInitComplete : function() {
      if ($(this).find('tbody tr').length<=1) {
         $(this).parent().hide();
      }
   } 
});

Reference Link – https://stackoverflow.com/questions/19296736/how-to-make-invisible-datatable-when-there-is-no-data

LEAVE A REPLY

Please enter your comment!
Please enter your name here