Implement Access Control to the Editor buttons?

Implement Access Control to the Editor buttons?

Ali AdnanAli Adnan Posts: 47Questions: 18Answers: 1

Hi Allan,

With Reference of this Question
https://datatables.net//forums/discussion/comment/72266/#Comment_72266

Is there any update about how can I show hide Dynamically Editor buttons ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin
    Answer ✓

    button().add() can be used to dynamically add a button and button().remove() to dynamically remove a button.

    Allan

  • Ali AdnanAli Adnan Posts: 47Questions: 18Answers: 1

    Dear Allan,

    As suggested by you I am doing Like this.

    CBD_main_Table = $('#dt_contractors').DataTable({
                        "sDom": "B<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>" +
                            "t" +
                            "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
                        ajax: {
                            url: CBD_main_strURL,
                            type: 'POST'
                        },
                        "bDestroy": true,
                        "iDisplayLength": 10,
                        "oLanguage": {
                            "sSearch": '<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>'
                        },
                        "columnDefs": [
                            {
                                targets: 5,
                                render: $.fn.dataTable.render.ellipsis(50)
                            }
                        ],
                        "columns": [
                        { data: "cdb_contractors.cont_id" },
                        { data: "cdb_contractors.cont_code" },
                        { data: "cdb_contractors.cont_desc" },
                        { data: "cdb_contractors.cont_desc_ar" },
                        { data: "cdb_contractor_grade.g_desc" },
                        { data: "cdb_contractors.cont_email" },
                        { data: "cdb_contractors.sms_gsm" }
                        ],
                        "order": [[0, 'asc']],
                        initComplete: function () {
                            console.log('dt_contractors DataTables has finished its initialisation.');
                            this.api().row({ order: 'current' }, 0).select();
                        },
                        select: {
                            style: 'single'
                        },
                        buttons: [
                            { extend: 'create', editor: CBD_main_editor },
                            { extend: 'edit', editor: CBD_main_editor },
                            { extend: 'remove', editor: CBD_main_editor }
                        ]
                    });
    
    ApplyPageAccess(UAccPageRightsData);
    
    
    function ApplyPageAccess(P_USER_RIGHTS) {
                        var CreateButton = '1';
                        var EditButton = '2';
                        var DeleteButton = '3';
    
                        if (P_USER_RIGHTS.length > 1) {
    
                            if (P_USER_RIGHTS.indexOf("DELETE") == -1) {
                                console.log("Not Authorize to Delete Records");
                               // below line through error 
                              // Uncaught TypeError: Cannot read property 'node' of undefined
                                CBD_main_Table.button(DeleteButton).remove();
                            }
    
                            if (P_USER_RIGHTS.indexOf("UPDATE") == -1) {
                                console.log("Not Authorize to Modify/Edit Records");
                                CBD_main_Table.button(EditButton).remove();
                            }
    
                            if (P_USER_RIGHTS.indexOf("INSERT") == -1) {
                                console.log("Not Authorize to Create Records");
                                CBD_main_Table.button(CreateButton).remove();
                            }
                        }
                        else {
                            CBD_main_Table.button(CreateButton).remove();
                            CBD_main_Table.button(EditButton).remove();
                            CBD_main_Table.button(DeleteButton).remove();
                        }
    
                    }
    

    ERROR in CONSOLE


    cdb_server:1436 Not Authorize to Delete Records datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 Uncaught TypeError: Cannot read property 'node' of undefined at f (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at Function.e.buttonSelector (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at e.<anonymous> (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at e.iterator (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at e.<anonymous> (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at e.buttons (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at e.<anonymous> (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at e.button (datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1) at ApplyPageAccess (cdb_server:1437) at HTMLDocument.<anonymous> (cdb_server:1300) f @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 e.buttonSelector @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 (anonymous) @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 iterator @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 (anonymous) @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 (anonymous) @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 (anonymous) @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 (anonymous) @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 ApplyPageAccess @ cdb_server:1437 (anonymous) @ cdb_server:1300 l @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 fireWith @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 ready @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 ct @ datatables?v=B6BihADtm4dTrLyRJD3lknos1GB04AdkF6Pkbb7T4QA1:1 cdb_server:884 dt_contractors DataTables has finished its initialisation.

    Please Help me

  • Ali AdnanAli Adnan Posts: 47Questions: 18Answers: 1

    Dear Allan,
    as mentioned below
    https://datatables.net/reference/type/button-selector

    I extend the Editor button by name and select as follow and now it working as expected.

    buttons('remove:name').remove();
    

    Sorry for my misunderstanding and above post.

    Thanks

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    Good to hear you've got it working now.

    Allan

This discussion has been closed.