jQuery数据表隐藏了thead

3 jquery jquery-datatables

我想隐藏数据表thead如果表没有任何数据.

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];
        });
    }
Run Code Online (Sandbox Code Playgroud)

我认为如果表没有任何数据隐藏thead有利于为用户显示任何消息,如何隐藏?

小智 13

试试这个:

"fnDrawCallback": function ( oSettings ) {
    $(oSettings.nTHead).hide();
}
Run Code Online (Sandbox Code Playgroud)

每个'draw'事件都会调用"fnDrawCallback"函数,并允许您动态修改所需的有关创建的DOM的任何方面.

  • 似乎还有另一种简单方法可以隐藏<thead> - http://stackoverflow.com/questions/6732254/how-to-supress-table-headers-completely-in-jquery-datatables (2认同)

chr*_*ris 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();
}
Run Code Online (Sandbox Code Playgroud)