12

How do I to hide jQuery datatables, when I want to toggle the datatable's visibility? The problem is if I write hide statement it only hides the rows, not the headers and footer. How can I hide datatable fully?

For hiding, I used the below code:

 var oTable = $('#example').dataTable(); // 'example is the table id'
 oTable.hide();
Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
Rajaram Shelar
  • 7,537
  • 24
  • 66
  • 107

3 Answers3

23

Try this

$('#example').parents('div.dataTables_wrapper').first().hide();
msapkal
  • 8,268
  • 2
  • 31
  • 48
16

i think the best way is to include the table inside a div and hide the div

 <div id='divTable'>
     <table>
     </table>
 </div>

 $('#divTable').hide();
badr slaoui
  • 1,023
  • 11
  • 27
0

For me (and I know this is a wierd need) I needed to hide the main table but keep the results (i.e. X results of X filtered).

$('div.dataTables_wrapper thead,div.dataTables_wrapper tbody').hide();

The above fixed it for me. If you have a footer you would need to add ,div.dataTables_wrapper tfoot as well.

Antony
  • 3,875
  • 30
  • 32