Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables + hiding all columns button

Tags:

datatables

in datatables I want to be able to hide all columns, but can't seem to get the syntax right.

This from the code below and the above link, creates a button that shows all the columns. Is there a way to write this so that I can hide all columns?

        {
            extend: 'colvisGroup',
            text: 'Show all',
            show: ':hidden'
        }

code:

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'colvisGroup',
                text: 'Office info',
                show: [ 1, 2 ],
                hide: [ 3, 4, 5 ]
            },
            {
                extend: 'colvisGroup',
                text: 'HR info',
                show: [ 3, 4, 5 ],
                hide: [ 1, 2 ]
            },
            {
                extend: 'colvisGroup',
                text: 'Show all',
                show: ':hidden'
            }
        ]
    } );
} );

i have tried something like the below with other permutations, but no joy, can anyone advise, and/or how I might find it in the documentation.

{
    extend: 'colvisGroup',
    text: 'Show None',
    visibility: false
}
like image 240
HattrickNZ Avatar asked Jun 29 '26 11:06

HattrickNZ


1 Answers

{
    extend: 'colvisGroup',
    text: 'Show None',
    hide: [':gt(1)'],
    //show: [0, 1, 2],
    //hide: [0, 1, 2],
    //hide: ['*']
}

this worked for me, only 2 column visible...

like image 86
Burak YILDIRIM Avatar answered Jul 06 '26 09:07

Burak YILDIRIM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!