Disable Edit, or read only row

Disable Edit, or read only row

wkeullwkeull Posts: 12Questions: 4Answers: 0

I have the need to either disable the edit button. I have been successful with the js to select this data however it seems that the underlying scripts prevent this enable/disable from operating as expected for example via:
table.button( 1 ).enable( data === 1 );

Is there a means that I am over looking to make this function as intended? Alternatively, another option would be to mark a row as read only, is this a possibility?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin
    Answer ✓

    The edit button has its own enable and disable code via the selected (source code) which will do its own enable / disable. I suspect that is what is interfering with your own.

    I'd suggest providing your own init function for your button which should add whatever event handlers you need - that will override the original, making sure that there will be no conflict.

    Allan

  • wkeullwkeull Posts: 12Questions: 4Answers: 0
    edited December 2017

    Allan,
    Thanks for the help that was exactly the direction I needed to go. The below was successful:

    // Display the buttons
    new $.fn.dataTable.Buttons( table, [
        { extend: "create", editor: editor},
        {
            text: 'Edit',
            init: function ( dt, node, config ) {
                this.disable();
                }
        }
    ] );
    
      //enabledisable based on cell value
     table.on( 'select', function () {      
        var data = table.rows( { selected: true } ).data();
        data = parseInt(data[0]['work_status']['step_complete']);
        table.button( 1 ).enable( data === 1 ?
                false :
        true
        );
    } );
    
This discussion has been closed.