jQuery DataTables hide column without removing it from DOM

后端 未结 5 1884
囚心锁ツ
囚心锁ツ 2020-12-30 01:22

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 proper

5条回答
  •  生来不讨喜
    2020-12-30 01:35

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

提交回复
热议问题