Hide a custom button collection after initComplete doesn't work

Hide a custom button collection after initComplete doesn't work

itajackassitajackass Posts: 121Questions: 37Answers: 3
edited March 2018 in Free community support

I need to hide some buttons not needed based on query variable url.

I've this but doesn't work (but alert is fired correctly):

 "initComplete": function(settings, json) {
        alert( 'DataTables has finished its initialisation.' );

        //  HIDE

        var type = getParams(window.location.href)['type'];

        if ( type != "ddt" ) {

                            alert("I'm going to hide");

            $(".dt_btn_ddt_converti_fattura").css("display","none");

        }

    },buttons: [
        {
            extend: 'collection',
                            text: 'Selected',
            buttons: [
                {
                    text: 'DDT: Trasforma Fattura',
                    className: 'dt_btn_ddt_converti_fattura',
                    action: function () {

                        ...

                    }
                },
                {
                    text: 'Invoice: Set done',
                    className: 'dt_btn_fattura_done',
                    action: function () {

                        ...

                    }
                }

            ]
        },

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,161Questions: 1Answers: 2,588

    Hi itajackass,

    I just tried it here, and it works for me - I'm hiding the XLS button in initComplete.

    So it's something to do with the test you have around the hide action - the type != "ddt". I'd say debug those values, as the hiding itself will work!

    Cheers,

    Colin

  • itajackassitajackass Posts: 121Questions: 37Answers: 3

    Hi, thanks for the reply. My problem is when the button is inside a COLLECTION. See your code updated. http://live.datatables.net/pusowihu/1/edit

  • colincolin Posts: 15,161Questions: 1Answers: 2,588
    Answer ✓

    Making progress! :)

    There's two lines now in the initComplete - one disables the buttons (button().disable()), the other removes them entirely (button().remove()). button().add() can be used to re-add it again.

    I hope that does the trick!

    C

  • itajackassitajackass Posts: 121Questions: 37Answers: 3

    Wow it's perfect! Thanks!!!! :)

This discussion has been closed.