Restrict to at least one visible column at all times + hide/show all

Restrict to at least one visible column at all times + hide/show all

legshooterlegshooter Posts: 6Questions: 2Answers: 0
edited July 2016 in Free community support

Hey,

I'm using the extended colvis collection.

  1. Is there any way to force at least one column to be selected at all times? i.e. If only 1 column is visible and the user tries to click it in order to hide it, it won't work. Is there any callback I can somehow make this check in, and return false when requesting to hide the only 1 visible column?

  2. Also, similarly to colvisRestore, I need directions on how to add a hide/show all columns behavior to the top of the collection (with prefixButtons I guess), preferably in a single toggle button. Any directions?

I need to think of a way to make 'hide all' respect the at least 1 visible column at all times restriction I'm looking to implement. But I'm getting ahead of myself since I don't even know if all of this is possible.

Thanks.

Answers

  • legshooterlegshooter Posts: 6Questions: 2Answers: 0

    Solved 1 for now:

    dt.on('column-visibility', function (e, settings, column, state) {
      if (dt.columns(':visible').count() === 1) {
        dt.column(column).visible(true);
      }
    });
    

    Unfortunately the event doesn't support preventing the default, so it's kinda hacky, but it's the best I've got atm.

This discussion has been closed.