Column grouping show/hide with 'colvis' ?

Column grouping show/hide with 'colvis' ?

TishmanTishman Posts: 4Questions: 2Answers: 0

I was wondering if theres a way to pair or group columns together into one button while using colvis.
I found an older forumn post asking about it in the depricated ColVis : https://datatables.net/forums/discussion/8052 and wasnt sure if any progress was made on that in the new version.

It looks like the functionality exist in columnToggle, however I would like to add the button into the already existing 'colvis' collection.

For more clarity:
I have these two columns:

one column is a date, the other is just an icon which indicates a state (related to the date). I would like to be able to hide both the date and the icon columns under one button, rather than 2 separate buttons that colvis generates.

Is there a way to do accomplish this?
Thanks,
-Tish

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @Tishman,

    Yep, see this column groups example here.

    Cheers,

    Colin

  • TishmanTishman Posts: 4Questions: 2Answers: 0

    Thanks! I looked into it and ended with this result, which is exactly what Im looking for:

     buttons: [
            {
                extend: "colvis",
                postfixButtons:[{extend: 'columnToggle', text:'Due Date',columns:':gt(9)'}],
                titleAttr: 'Column Visibility',
                text: 'Column Visibility',
                background: false,
                fade:0,
                columns: ':gt(1)'
            }
      ]
    

    Emphasis on the postfixButton line. Thats the code snippet added to make it function how I wanted.

This discussion has been closed.