简体   繁体   English

如何隐藏DataTables中的标题行?

[英]How do I hide the header row in DataTables?

I want to hide the header row from appearing, being visible on the table. 我想隐藏表头行,使其不可见。 (Both when viewed from desktop and mobile) (从台式机和移动设备上观看时)

I tried: 我试过了:

"drawCallback":function(settings ){$("#mySelection thead").remove();} ,

While this code seems to render the table the way I want (header-less), it also effects the output of the buttons used here. 尽管这段代码似乎以我想要的方式呈现了表格(无标题),但它也影响了此处使用的按钮的输出。 The buttons are set to output whatever is visible (toggled by column visibility). 这些按钮设置为输出任何可见的(由列可见性切换)。

And unfortunately this code removes not just the theader in the export output, but also all the data that was in the tables. 不幸的是,此代码不仅删除了导出输出中的剧院,而且还删除了表中的所有数据。

The same thing happens when I try: 当我尝试时会发生相同的事情:

$("#mySelection thead").hide()

Is there anyway to keep the output as it was before and only hide the table headers from view, as in just the row with the column titles? 无论如何,是否仍要像以前一样保留输出,并且仅在视图中隐藏表标题,就像在带有列标题的行中一样? I want to keep the buttons (copy, excel, pdf, colvis) working on the table data. 我想保持表格数据上的按钮(复制,excel,pdf,colvis)正常工作。

https://jsfiddle.net/287fum2q/ https://jsfiddle.net/287fum2q/

EDIT: 编辑:

Using the following code in the CSS results in the problem I mentioned in the first part of my question: 在CSS中使用以下代码会导致在问题的第一部分中提到的问题:

.ui.table thead { display: none !important; }

As does this: 就像这样:

thead { display: none!important; }

If you could include a saved jsfiddle that shows the solution, that'd be all the more helpful. 如果您可以包括保存的jsfiddle来显示解决方案,那将更加有用。

thead css was conflict with semanticui.min.css so used !important to overwrite css thead css与semanticui.min.css thead发生冲突,因此使用!important覆盖css

.ui.table thead {
    display: none !important;
}

It appears the DataTables Jquery plugin may possibly have a bug. 看来DataTables Jquery插件可能存在错误。 DataTables assumes the header display will not be set to none . DataTables假定标题显示不会设置为none When you set the header display:none it prevents the DataTables buttons from working as expected. 当您设置标题display:none它会阻止DataTables按钮按预期方式工作。

Here's your workaround : 这是您的解决方法

  .ui.table thead {
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
  } 

This removes the header from sight, but the DataTables buttons still have what they need to work correctly. 这样可以使标题不可见,但是DataTables按钮仍然具有正常工作所需的功能。 I just learned this can be good practice (surprisingly) because display:none makes content "inaccessible" to screen readers. 我刚刚了解到这可能是一个好习惯(令人惊讶的是),因为display:none 使得屏幕阅读器“无法访问”内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM