Responsive toggle visibility
Responsive toggle visibility
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
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
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.
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
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. :-(
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
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.
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:
I'll push it out to the site next week.
Regards,
Allan