Responsive toggle visibility

Responsive toggle visibility

beOhBEbeOhBE Posts: 4Questions: 1Answers: 0
edited May 2016 in Free community support

Is there a preferred way of toggling column visibility in a datatable that is using the Responsive extension?

This table is within an Angular app. I have responsive set to 'true in dt-options. In dt-column-defs I have hidden 5 columns using this line:
DTColumnDefBuilder.newColumnDef([6,7,8,9,10]).withClass('never')

When the user clicks on checkboxes I'd like to be able to toggle the visibility of those columns. Is this possible in Responsive?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin
    Answer ✓

    With Responsive 2 you can use DataTables' columns().visible() method just as you would with a non-responsive table. Responsive 2 implements its own column hiding, so the column visibility methods are orthogonal to that.

    Allan

  • beOhBEbeOhBE Posts: 4Questions: 1Answers: 0

    Oh great. That helped a bunch. I was using the documentation on the site and I didn't think I could use that method with Responsive.

    Thanks again for the quick response and also for the great product.

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    Its possible I missed part of the documentation when updating it for v2. Could you link me to the part that mislead you so I can correct it please?

    Thanks,
    Allan

  • beOhBEbeOhBE Posts: 4Questions: 1Answers: 0

    That note about not being able to use columns.visible() was on the angular-datatables site: http://l-lin.github.io/angular-datatables/#/withResponsive

    And I just realized that apparently I can't use Responsive 2 with angular-datatables so I'm back where I started. :-(

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    Thanks for pointing that out - their documentation is out of date in that case.

    Why can't you use Responsive 2 with angular-datatables? I've not used it much myself, so I'm not that familiar with it.

    Allan

  • beOhBEbeOhBE Posts: 4Questions: 1Answers: 0

    Well according to their site (http://l-lin.github.io/angular-datatables/#/gettingStarted), it's only been tested with Responsive 1.0.1 and we don't want to risk something breaking in our project down the line.

    btw, I noticed a few out-of-date lines of copy on datatables.net as well:

    On the Class Logic page (https://datatables.net/extensions/responsive/classes) under the Special Classes heading, "...Responsive will also detect the three following special classes". This was my first clue that the "never" class was a more recent addition.

    hmm, there was another spot where I noticed a reference to "three special classes" but I can't locate it now.

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    The text on the classes page is actually still correct, but perhaps not complete. I've just commit a change that will update it to read:

    • never - Column will never be visible, regardless of the browser width and the data will not be shown in a child row (<span class="since">1.0.2</span>). Note as of <span class="since">Responsive 2.0.0</span> this option is no longer required as v2 fully supports DataTables' native column visibility (i.e. use columns.visible or column().visible() to hide a column).

    I'll push it out to the site next week.

    Regards,
    Allan

This discussion has been closed.