How do I disable an inline cell, if its previous cell contains specific values

How do I disable an inline cell, if its previous cell contains specific values

nm_DeeDubnm_DeeDub Posts: 2Questions: 1Answers: 0
edited May 27 in Free community support

I would like to be able to disable (for editing) a cell, if the cell before holds a specific value.

By way of an example, I have a table that has a header row, and two data rows. There are only 3 cell headers titled Id, Type and Value.

The Type values are dropdown lists. When I select a particular value from the dropdown list, I want to be able to disable the "Value" column.

I want this per row.

Answers

  • allanallan Posts: 64,521Questions: 1Answers: 10,666 Site admin

    Use the dependent() method.

    This example shows it doing show / hide, but you could just as easily do enable / disable.

    Allan

  • nm_DeeDubnm_DeeDub Posts: 2Questions: 1Answers: 0

    Thanks allan, but I'm doing this inline.

  • allanallan Posts: 64,521Questions: 1Answers: 10,666 Site admin

    Put an if condition around the call to inline() which checks the data for the row and sees if it should be editable or not:

    table.on('click', 'tbody td', function () {
      let rowData = table.row(this.closest('tr')).data();
    
      if (rowData.isAllowedToEdit) {
        editor.inline(this);
      }
    });
    

    Obviously you might want to add some variance for the specific column / cell clicked on, but that would be the basic idea.

    Allan

Sign In or Register to comment.