ColVis: postfixButtons disappear on ColReorder

ColVis: postfixButtons disappear on ColReorder

vipexvipex Posts: 1Questions: 1Answers: 0

Link to test case: http://live.datatables.net/fatahetu/1/
Description of problem:
The problem happens when ColVis is configured to have postfix buttons (in my case is the ColVisRestore one) and ColReorder is enabled.
Once a column is moved, the ColVis menu is reordered but the postfix buttons are lost.

Answers

  • khaoskhaos Posts: 47Questions: 11Answers: 0

    Thanks for figuring out the intermittent issue! Did you ever find a fix?

  • marrowmarrow Posts: 2Questions: 0Answers: 0
    edited December 2022

    I'm having the same problem. This was also reported back in Sept 2021 with prefixButtons, and @colin mentioned DD-2192 for reference internally. Would love to see a fix for this!

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Hi,

    Apologies that this one dropped off the radar somewhat. I've just been looking into it and it is due to the mutable nature of our button configurable objects. When a button is setup we extend its options, potentially overwriting some data used to set it up in the first place.

    That has actually been a bit of a pain point in Buttons right from the start and I will look into holding a clone of the configuration object to resolve that.

    In the meantime there is a workaround. Rather than using:

                {
                    extend: 'colvis',
                    postfixButtons: [ 'colvisRestore' ]
                },
    

    You can use:

                {
                    extend: 'collection',
                    buttons: [ 'columnsToggle', 'colvisRestore' ]
                }
    

    columnsToggle is just a list of all the columns, so it is basically the same thing.

    Allan

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    I've committed a fix for this specific issue - however, it actually results in another issue coming to the surface. Because the "restore" button caches the column visibility state when the button is initialized, and a rebuild of the list reinitialize the button... the state it will restore to is the column visibility after the last column reordering.

    I don't have an immediate fix for that unfortunately. If the restore button was at the top level it would work fine since its the same button as used at the start. I need to think more on this one.

    So close...

    Allan

  • marrowmarrow Posts: 2Questions: 0Answers: 0

    This is amazing, thank you @allan! Instead of using colvisRestore, I have a class-based "show all" button similar to the earlier test case, as well as another custom postfixButton. Your workaround fixed the problem like a charm. Thanks so much for looking into it!

Sign In or Register to comment.