hide column in datatable using jquery code example

Example 1: datatables dynamically hide columns

const table = $('#example').DataTable();

// Get the column API object
const column = table.column( 2 ); // gets 2nd column (0-indexed)
 
// Toggle the visibility
column.visible( ! column.visible() ); // true or false

Example 2: how to filter on a hidden column datatables

Plain text12345678910111213141516171819202122232425262728293031323334353637383940414243444546$(document).ready( function () {    $('#example').DataTable(    {                 responsive: true,        scrollY:'40vh',        scrollCollapse: true,        columnDefs: [        { targets: [0, 3, 4, 5, 7, 8, 9, 11, 12], visible: true},        { targets: '_all', visible: false },                 { width: "40%", targets: [5] }    ],                          "order": [[ 0, "asc" ]],        rowGroup: {                         enable: true,            dataSrc: 1,        },         initComplete: function () {            this.api().columns([1]).every(function () {                var column = this;                var select = $('<select><option value=""></option></select>')                    .appendTo( $(column.footer()).empty() )                    .on( 'change', function () {                        var val = $.fn.dataTable.util.escapeRegex(                            $(this).val()                        );                          column                            .search( val ? '^'+val+'$' : '', true, false )                            .draw();                    } );                  column.data().unique().sort().each( function ( d, j ) {                    select.append( '<option value="'+d+'">'+d+'</option>' )                } );            } );        }}         );     } );