Hide column from columnsToggle button dropdown

Hide column from columnsToggle button dropdown

jLinuxjLinux Posts: 981Questions: 73Answers: 75
edited September 2015 in Free community support

This is like the 3rd time ive changed the entire thread, but while its here, ill make some use of it.

I have a "Status" column in my table, I want users to be able to filter the table using the data, but I dont want the column to ever be visible, so I want to hide it from the colvis button dropdown.

The documentation says I should be able to specify which ones to show/hide by using the column-selector, but im having an issue getting it to work.

http://datatables.net/reference/type/column-selector

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited September 2015

    Heres an example table header..

    <table id="data-table" class="table width-full display compact table-condensed">
        <thead>
        <tr>
            <th id="creator">Creator</th>
            <th id="created">Created</th>
            <th id="modifier">Modifier</th>
            <th id="modified">Modified</th>
            <th id="status" data-visible="false">Status</th>
            <th id="server_hostname">Server Hostname</th>
            <th id="operating_system">Operating System</th>
            <th id="applications">Applications</th>
            <th id="monitoring">Monitoring</th>
        </tr>
        </thead>
        <!--- table stuff --->
    </table>
    

    Can I show any column that doesnt have the data-visible ?

    Edit Nevermind! got it working..

    new $.fn.dataTable.Buttons( $assets_dt, {
        buttons: [
            {
                extend: 'collection',
                text: 'Select Columns',
                buttons: [ {
                    extend: 'columnsToggle',
                    columns: ':not([data-visible="false"])'
                } ],
                className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn toolbox-delete-selected'
            }
        ],
        fade: true
    } );
    
This discussion has been closed.