Add sub-button to collection dynamically

Add sub-button to collection dynamically

brunorr.dvabrunorr.dva Posts: 2Questions: 1Answers: 0

Guys,
Does anyone know, how can I add a sub-button to a button collection?

I tried table.button().add( 'collection index'..., but didn't work :neutral:

Answers

  • Rob BrunRob Brun Posts: 56Questions: 2Answers: 14
    edited May 2017

    Hi brunorr.dva, I have been able to do this in my applications, it is a bit touchy though. Make sure you have the table instance, and the collection index correct

    function addAButton(table){
     
    table.button().add(2, {
           text: "Subscribe",
            action: function (e, dt, node, config) {
                   //   code you want to run
                        },
            enabled: true
        });
    }
    

    This will insert a custom button at the 2 index in your button collection.

  • brunorr.dvabrunorr.dva Posts: 2Questions: 1Answers: 0

    Hi Rob,

    Thank's for your reply, but what I need is to add a button to a button that extends 'collection' (https://datatables.net/extensions/buttons/examples/initialisation/collections.html).

  • 兔纸乏了兔纸乏了 Posts: 1Questions: 0Answers: 0

    I have the same need, but I can't find the answer. Do you know the solution?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Hi,

    The documentation for button().add() notes that the index parameter can be:

    A string with a dash (-) separator if the button is to be inserted into a collection (please refer to the button-selector documentation for full details of button indexes, including how they apply to collections of sub-buttons),

    Example: http://live.datatables.net/nexesufe/1/edit

    Allan

This discussion has been closed.