0

How to disable row checkbox based on the cell value in Datatables. Have table and few columns have data like System. If it is system need to disbale the row. Tried below code, checkboxes are not disabled.

this.dtOptions = {
  ajax: 'assets/test.json',
  initComplete: function (settings, json) {
    $.each(json.data, function (index, value) {  
      if(value.matchType == "System"){ //working
        $("table").closest('tbody tr td').find('input:checkbox').prop('disabled', true);
      } 
  }); 
  },
2
  • In your code where you compare cell value? Commented Nov 9, 2020 at 8:22
  • In conditional statement if(value.matchType == "System") Commented Nov 9, 2020 at 8:49

2 Answers 2

1

I your code, if index is your row index then you can try this

this.dtOptions = {
  ajax: 'assets/test.json',
  initComplete: function (settings, json) {
    $.each(json.data, function (index, value) {  
      if(value.matchType == "System"){ //working
        $("table tr").eq(index).find('input:checkbox').prop('disabled', true);
      } 
  }); 
  },
Sign up to request clarification or add additional context in comments.

Comments

0

The response from @Yuvraj inspired me the following solution with the "createdRow" event

'createdRow': function (row, data, dataIndex) {
    if (!data.isAvailable /* some condition based on data */) {
        $(row).find('input:checkbox').prop('disabled', true);
    } 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.