How to selectively bring responsive detail columns to the foreground
How to selectively bring responsive detail columns to the foreground

Hello,
I'm looking for advice on the best approach for selectively un-hiding columns that are hidden by the responsive extension either because of the width of the table or because of class names. The opposite is also true. I'd like to selectively relegate columns to details. In looking through the documentation I have seen colReorder and the visibility button advertised as ways to control the responsive column visibility, but I've found these to be contrary to expectations. colReorder doesn't really have any effect on what columns are shown, and the visibility buttons do not bring columns out of the detail row and into the table. A column in the detail row is visible according to the button state. Clicking its button will actually remove that column from all the details, which is not what I would have expected. I'm considering working on a custom set of buttons that change responsive priorities, probably as an extension of the visibility button logic. Any advice would be appreciated. Thanks.
Regards,
Matt
This question has an accepted answers - jump to answer
Answers
you could assign classes to the columns dynamically according to the values of the respective buttons. Subsequently do a responsive.recalc() and columns.adjust(). You'll find these in the docs by searching.
It might not work because some of the input values are set during dt initialization. Then you would need a page refresh. But you'll figure it out
Thank you for this advice. I will see whether I can extend the colVis button and override its functionality in order to make it work better with responsive for my purposes.
I have come up with a solution that works, but I'm not entirely happy with it. I was not able to simply override parts of the existing colVis button because I couldn't work out how to get at the functions brought in through the "extends" chain, so I had to resort to making my own extension which provides all the same layers. Here is the code of my extension, which I've named colvisResponsive (and colvisResponsiveRestore):
Note, I did not change the spec of the covisGroup button because I'm not using groups and I haven't looked at the use cases. Everything else works very well though. The state of the buttons are correct and they react immediately to other columns automatically coming in and out due to singular additions or substractions. If someone can tell me how I could have done this without creating the entire new extension, I'd be grateful.
As an aside, I was surprised that the built in colVis button did not work this way when combined with responsive. In my opinion, the button should be aware of responsive if it is loaded. Thanks.