Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DataTables hide column without removing it from DOM

Tags:

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.

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.

I am populating the table using aaData property using server side pagination.

Had a look at this question but these options remove it from the DOM. jquery datatables hide column

like image 774
Rohit Banga Avatar asked Jan 17 '13 05:01

Rohit Banga


People also ask

How do I hide and show columns in DataTable?

To hide and show columns use columns() and visible() method. Call it on dataTables instance and pass column index in columns() method and false to visible() method. Similarly, pass true to visible() if you want to show the columns.

How do I hide a column in lightning DataTable?

The only thing you need to do is removing the desired element from the columns array, or use the original set if you want it back.

What is FixedColumns in DataTables?

FixedColumns provides the option to freeze one or more columns to the left or right of a horizontally scrolling DataTable. This allows information in the fixed columns to remain visible even when scrolling through the data set. This can be particularly useful if you wish to show a large number of columns.


1 Answers

You should use className along with the columnDefs or the columns,

Define hide_column class in your css like this

.hide_column {     display : none; } 

You have two ways to assign that .hide_column class:

Use columnDefs (assign custom class to first column):

$('#example').DataTable( {   columnDefs: [     { targets: [ 0 ],       className: "hide_column"     }   ] } ); 

OR columns

$('#example').DataTable( {   "columns": [     { className: "hide_column" },     null,     null,     null,     null   ] } ); 

code snippets taken from here


Old answer

Try adding

"sClass": "hide_column" 

that should make that column hidden...

like image 68
Daniel Avatar answered Sep 28 '22 01:09

Daniel