How to remove a remove-extended button

How to remove a remove-extended button

ka107ka107 Posts: 3Questions: 0Answers: 0
edited October 2019 in Buttons

Hello,

I am trying to remove programmatically this type of buttons (during its own init method) like that:

{ 
                        extend: 'remove', 
                        name: 'deleteParticipant',
                        init: function ( dt, node, config ) {
                            switch(profile) {
                                case 'Student':
                                case 'Staff':
                                    table.button('deleteParticipant:name').remove(); // not working!
                                    break;
                                default: //Admin
                                    //alert('No way!');
                            }
                        },
                        editor: editor,
                        formButtons: [
                            'Delete',
                            { text: 'Cancel', action: function () { this.close(); } }
                        ]
}

Removing create-extended buttons this way is working well...

Thanks!

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @ka107 ,

    That seems like an odd thing to do. Can you give some context please as to the problem you're trying to solve so we can get a better understanding.

    Cheers,

    Colin

  • ka107ka107 Posts: 3Questions: 0Answers: 0

    depending of the profile from the logged in user, I would like to remove some buttons.

    In this case, I don't want students and staff to have access to the 'Delete' button (disabling is working fine but I'd prefer removing that buttons)

    It's weird that the same thing is working right for the rest of the buttons but not for this

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @ka107 ,

    I tried it, and it gives an error - not too surprising I guess given it's removing itself in its own function. If you want to use button().remove(), it would be better to do this in initComplete. Alternatively, you can just button().disable() it and hide it within the buttons.buttons.init - like this here: http://live.datatables.net/ritolure/1/edit

    Cheers,

    Colin

  • ka107ka107 Posts: 3Questions: 0Answers: 0

    thanks for the info, finally I realized its better to do at initComplete

This discussion has been closed.