Show Edit button on conditions

Show Edit button on conditions

PaulineRPaulineR Posts: 2Questions: 1Answers: 0
edited October 2017 in Buttons

Hello,

Is it possible to show button based on external condition ?

buttons: [
                    {
                        extend: 'pdfHtml5',
                        className: 'btn-datatable',
                        orientation: 'landscape',
                        pageSize: 'LEGAL',
                    },
                    {
                        extend: 'print',
                        className: 'btn-datatable',
                        text : 'Imprimer',
                        orientation: 'landscape',
                        pageSize: 'LEGAL',
                    },
                    {
                        extend: 'excel',
                        className: 'btn-datatable',
                    },
                    {
                        extend: 'colvis',
                        collectionLayout: 'two-column',
                        text : 'Colonne Visible',
                        className: 'btn-datatable',
                    },
                    {
                        extend: 'edit',
                        editor: editor,
                    },


                ],

I'd like to show the "Edit" button if the user has certain right.

Thanks !

Pauline.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 54,680Questions: 1Answers: 8,552 Site admin
    edited August 2019 Answer ✓

    Yes - the API methods button().show() and button().hide() can be used.

    Another option is to simply put an if condition around the button:

    var buttons = [];
    
    if ( accessButton1 ) {
      buttons.push( ... );
    }
    
    if ( accessButton2 ) {
      buttons.push( ... );
    }
    
    ...
    
    // In Table Init
    buttons: buttons
    

    Allan

    Note - these methods do not exist in 2019 - links removed

  • PaulineRPaulineR Posts: 2Questions: 1Answers: 0

    Thank you Allan !

This discussion has been closed.