jQuery DataTables 隐藏列而不将其从 DOM 中删除 [英] jQuery DataTables hide column without removing it from DOM
问题描述
我需要隐藏一列,使其不显示在 jquery 数据表中.当我使用 bVisible 属性隐藏列时,它会从 DOM 中消失.
I need to hide a column from showing up in jquery datatables. When I hide the column using bVisible property it disappears from the DOM.
我想将列的表格单元格的显示属性设置为无,以便这些值不会出现在视图中,但它们仍应存在于 DOM 中,因为我隐藏的列唯一地标识了该行,我需要知道行选择上的唯一 ID.如何实现这一目标.
I want to set display property of table cells of a column to none so that the values do not appear in the view but they should still be present in the DOM as the column I am hiding identifies the row uniquely and I need to know the unique ID on row select. How to achieve this.
我正在使用服务器端分页使用 aaData 属性填充表格.
I am populating the table using aaData property using server side pagination.
查看了这个问题,但这些选项将其从 DOM 中删除.jquery 数据表隐藏列
Had a look at this question but these options remove it from the DOM. jquery datatables hide column
推荐答案
您应该将 className
与 columnDefs 或 columns、
You should use className
along with the columnDefs or the columns,
像这样在 css 中定义 hide_column
类
Define hide_column
class in your css like this
.hide_column {
display : none;
}
您有两种方法可以分配 .hide_column
类:
You have two ways to assign that .hide_column
class:
使用 columnDefs
(将自定义类分配给第一列):
Use columnDefs
(assign custom class to first column):
$('#example').DataTable( {
columnDefs: [
{ targets: [ 0 ],
className: "hide_column"
}
]
} );
OR 列
$('#example').DataTable( {
"columns": [
{ className: "hide_column" },
null,
null,
null,
null
]
} );
代码片段取自此处
旧答案
尝试添加
"sClass": "hide_column"
这应该使该列隐藏...
that should make that column hidden...
这篇关于jQuery DataTables 隐藏列而不将其从 DOM 中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!