DataTable:如何隐藏表头?

时间:2015-02-18 20:47:15

标签: html css datatables jquery-datatables

我有两个使用DataTable的表:

  • top:完全匹配
  • bottom:related

这是他们现在的样子。

enter image description here

正如您所看到的,不需要在第二个表上显示表头。我想隐藏它。

我在CSS上尝试过使用它:

由于班级= inventory_related

.inventory_related table thead {

        display:none;

    }

我也试图取消整体:

       <thead class="thin-border-bottom ">

            <th>Catalog # </th>
            <th>Description</th>
            <th>Available Vials</th>

        </thead>

这也不起作用。

任何人都有关于如何隐藏我的第二个表头的任何建议?

感谢。

5 个答案:

答案 0 :(得分:4)

<table>
  <thead style='display:none;'>
    <th>header 1</th>
    <th>header 2</th>
  </thead>
  <tbody>
    <td>row value 1</td>
    <td>row value 2</td>
  </tbody>
</table>

答案 1 :(得分:2)

请参阅以下代码作为示例:

&#13;
&#13;
.inventory_related thead {
  display: none;
}
&#13;
<table>
  <thead>
    <th>header 1</th>
    <th>header 2</th>
  </thead>
  <tbody>
    <td>row value 1</td>
    <td>row value 2</td>
  </tbody>
</table>
<table class='inventory_related'>
  <thead>
    <th>header</th>
    <th>header 2</th>
  </thead>
  <tbody>
    <td>row value 3</td>
    <td>row value 4</td>
  </tbody>
</table>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

就我而言,设置

.inventory_related thead {    
    display:none;   
}

被列宽弄糊涂,而

.inventory_related thead {    
    visibility: collapse;   
}

似乎正在工作。

答案 3 :(得分:0)

如果<table>的类是inventory_related,则写下以下的CSS

.inventory_related thead {    
    display:none;   
}

答案 4 :(得分:0)

如果您想在jQuery(js)中执行此操作,则只需执行以下操作即可:

$("#datatableId").css("display", "none");

其中“ datatableId”是表的ID或包含该表的div标签。