Restore toggled columns except for ones initially hidden

Restore toggled columns except for ones initially hidden

silkspinsilkspin Posts: 152Questions: 34Answers: 5

I'm using colvis and I've also created a button to show all the toggled off columns at once. However, a couple of columns are hidden on page load because they are in child rows and only needed for search purposes. The show all makes the originally hidden columns appear again. Is there a way to exclude these columns?

buttons: [
  'colvis',
  {
    extend: 'columnVisibility',
    text: 'Show All Columns',
    visibility: true
  }
],

If it's not possible I'll just remove the button. Thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Easiest way is probably to use a custom button:

    buttons: [
      ‘colvis’,
      {
        text: ‘Show All Columns’,
        action: function (e, dt) {
          dt.columns(...).visible( true, false ); // show selected columns, false is to disable redraw calcs for speed
          dt.columns(...).visible( false ); // hide selected columns.
        }
      }
    ]
    

    Allan

  • silkspinsilkspin Posts: 152Questions: 34Answers: 5

    That seems to work perfectly Allan. Thanks a lot.

This discussion has been closed.