4

i want to hide datatable thead if table dont have any data.

oTable_topics =$('#showTopics').dataTable({
    "bLengthChange": false,
    "bStateSave": true,
    "iDisplayLength": 12,                               
    "bScrollCollapse": true,       
    "bJQueryUI": true,
    "bAutoWidth": false,
    "sAjaxSource": "server_processing.php",
    "sPaginationType": "full_numbers",
    "bProcessing": true
    });
    function clickRowHandler_topics() {
        $('#showTopics tbody tr').bind('click', function () {
            var aData = oTable_topics.fnGetData( this );
            iId_topics = aData[1];
        });
    }

i think if table dont have any data hiding thead is good for display any message for users, how to hide that?

madth3
  • 7,275
  • 12
  • 50
  • 74

3 Answers3

13

Try this:

"fnDrawCallback": function ( oSettings ) {
    $(oSettings.nTHead).hide();
}

"fnDrawCallback" function is called on every 'draw' event, and allows you to dynamically modify any aspect you want about the created DOM.

Aidas Josas
  • 131
  • 2
  • 4
  • To remove the grid header and footer (the `
    ` before and after `` you can do: `$(oSettings.nTableWrapper.firstChild).hide(); $(oSettings.nTableWrapper.lastChild).hide();`
    – Thomas Kekeisen Jun 02 '15 at 10:19
  • 2
    It seems that there is another easy method to hide - http://stackoverflow.com/questions/6732254/how-to-supress-table-headers-completely-in-jquery-datatables – Raja Oct 22 '15 at 13:31
5

I know this is an old question but answering for others as this was the top result while I was looking into how to do this.

DataTables 1.10 answer

"drawCallback": function() {
  $(this.api().table().header()).hide();
}
chris
  • 3,019
  • 23
  • 21
1

Try to add in this option:

"sDom": 'rt'

it will hide header and footer, but first,you still need to check whether there is return data or not.

madth3
  • 7,275
  • 12
  • 50
  • 74
yeyene
  • 7,297
  • 1
  • 21
  • 29