How can I use a custom action in a extended button?

How can I use a custom action in a extended button?

skiiiksskiiiks Posts: 3Questions: 1Answers: 0

Hi:
I have a "colvis" extended button, and I would like to do some custom actions when use clicks in each of the columns to make them visible or invisible:

            {
                extend: 'colvis',
                action: function ( e, dt, node, config ) {
                    // do some stuff
                }
            }

But, if I do this, the stuff is executed, but the "colvis" feature disappear :-(

Is there any way to do extra things when use clicks in each column to make it visible/invisible ?

Thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Listen for the buttons-action event on that button to do whatever it is you need to do. The issue is that by providing an action function you are overriding the default, which is to show the collection. Often you can workaround that by calling the original action method, but that is actually really tricky with the colvis button due to the way it is defined.

    buttons-action is the way to do this one.

    Allan

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    Actually - when I sat down and looked at it again I had a thought - you can trigger the collection action: http://live.datatables.net/qavatemi/2/edit .

    Allan

  • skiiiksskiiiks Posts: 3Questions: 1Answers: 0

    Thank you Allan !!! It worked ...
    is there any event for the clicks of each column name shown in the modal box of colvis ?
    if not, I can trigger with $('button.buttons-columnVisibility').on('click', ...
    but if there's any cleaner way ... ;-)

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @skiiiks ,

    You can also use the buttons-action as Allan suggested above, see here.

    Cheers,

    Colin

  • skiiiksskiiiks Posts: 3Questions: 1Answers: 0

    PERFECT ! thank you !

This discussion has been closed.