Despite good suggestions I think there still needs (another) answer.
- Using dataTables a
<table>
will never be empty – or:empty
– since dataTables enforces you to have a<thead>
and a<tbody>
- 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