Html DataTable:如何隐藏表头?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28593598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:32:09  来源:igfitidea点击:

DataTable : How to hide table header?

htmlcssdatatablesjquery-datatables

提问by

I have 2 tables using DataTable :

我有 2 个使用 DataTable 的表:

  • top: exact match
  • bottom : related
  • 顶部:完全匹配
  • 底部:相关

Here is what they look like right now.

这是他们现在的样子。

enter image description here

在此处输入图片说明

As you can see that, there is no need to show the table header on the second table. I want to hide it.

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

I have tried using this on my CSS :

我试过在我的 CSS 上使用它:

Since the class = inventory_related

由于班级= inventory_related

.inventory_related table thead {

        display:none;

    }

I also tried to take off the whole :

我也试图脱掉整个:

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

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

        </thead>

This doesn't work either.

这也行不通。

Anyone have any suggestion on how do I hide my 2nd table header ?

有人对如何隐藏第二个表头有任何建议吗?

Thanks.

谢谢。

回答by Mitch Roe

In my case, setting

就我而言,设置

.inventory_related thead {    
    display:none;   
}

messed with column widths, while

弄乱了列宽,而

.inventory_related thead {    
    visibility: collapse;   
}

seems to be working.

似乎正在工作。

回答by Nguy?n ??c Tùng

<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>

回答by CodeLikeBeaker

Please see the following code as an example:

请看以下代码为例:

.inventory_related thead {
  display: none;
}
<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>

回答by Tanjima Tani

if the class of <table>is inventory_relatedthen write the following css

如果类<table>inventory_related然后写下面的css

.inventory_related thead {    
    display:none;   
}

回答by Me_developer

If you want to do it in jQuery(js) then you can simply do:

如果你想在 jQuery(js) 中做到这一点,那么你可以简单地做:

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

where 'datatableId' is the ID of your table or some div tag which contains the table.

其中 'datatableId' 是您的表的 ID 或包含该表的某些 div 标签。