datatable - 根据媒体查询大小删除或隐藏特定(仅一个)数据表列
问题描述
我有一个响应式数据表,就像在这个例子中一样 https://editor.datatables.net/examples/extensions/responsive.html 但是我的一个列包含链接,这意味着当我的数据表折叠并且我单击展开按钮时,链接列扩展并破坏了我的网页的响应能力(表格应与顶部的绿色 jumbotron 对齐)
我尝试通过在 th 和目标 [4] 中添加类名来隐藏特定媒体查询上的链接列(4 是列链接的数量)然后添加一个 CSS 显示 none 但它只隐藏文本而不是整个列
@media (max-width: 700px) {
.hide {
display:none;
}
<th class="hide" width="30%">Link</th>
"targets": [4],
"className": "hide",
}
我也试过
@media (max-width: 700px) {
table th, table td{
display:none;
}
table th:nth-child(1), table th:nth-child(2), table th:nth-child(3), table th:nth-child(5), table th:nth-child(6),
table td:nth-child(1), table td:nth-child(2),table td:nth-child(3), table td:nth-child(5), table td:nth-child(6){
display:table-cell;
}
它仍然不起作用
您对如何隐藏特定媒体查询大小的列有任何想法。其他方法也受到欢迎,我唯一想要的就是让数据表始终响应。谢谢!
解决方案
通过将类名和 css 添加到 td 来解决
"columnDefs": [{
"targets": [4],
'createdCell': function (td) {
$(td).addClass('myclass');
}
}]
<th class="myclass" width="30%">Link</th>
@media (max-width: 700px) {
.myclass {
display:none!important;
}
}
推荐阅读
- subquery - InfluxDb 1.8 检索时间作为主查询的子查询
- c# - Entity Framework 和 Process.Start 阻止异步方法调用执行
- amazon-web-services - AWS Amplify:confirmSignUp 之后,自动登录用户的最佳实践是什么?
- c# - Delphi WSDL 返回零
- reactjs - 如何删除与 AppSync/Amplify 中的另一个项目相关的项目?
- python - Python - xarray mean between two netcdf files
- r - Modify all the strings between two sets of rows
- javascript - 向电子中的网页发出多行 javascript 调试器请求
- python - 删除 Json 文件 Python 中的对象
- c# - 使用 ReadOnlySpan 对二维数组进行不安全切片