简体   繁体   English

Angular 数据表:如何根据列数据禁用立即行复选框

[英]Angular Datatable: How to disable immediate row checkbox based on the column data

How to disable row checkbox based on the column data.如何根据列数据禁用行复选框。 Have one datatable and have to write one condition, if firstname="Superman", need to disable checkbox of the row.有一个数据表并且必须写一个条件,如果firstname="Superman",需要disable checkbox of the row. So not possible to select the checkbox again.所以不可能再次选择 select 复选框。 I tried with below code and I'm unbale to disable the checkbox.我尝试使用下面的代码,但我无法禁用该复选框。 I tried below code,我试过下面的代码,

this.http.get(dataUrl).subscribe(response => {
  // setTimeout(() => {
  this.persons = response.data;
  $.each(this.persons, function(key, value) {
    if (value.firstname == "Superman") {
      console.log("inside");
      // $('.checkboxCls').prop('disabled', true);
      $(this)
        .closest("tr")
        .find("input[type=checkbox]")
        .prop("disabled", true);
    }
  });
  this.dtTrigger.next();
  // });
});

Here is the working Stackblitz for reference.这是工作中的Stackblitz供参考。 Could you please suggest what is the issue.您能否提出问题所在。

You can disable the checkbox from the HTML template side.您可以从 HTML 模板端禁用该复选框。

    <td><input [disabled]="person.firstName === 'Superman'" type="checkbox" class="checkboxCls" name="id" [checked]="isChecked" value="{{person.id}}"></td>

Edited StackBlitz Code编辑StackBlitz代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM