【问题标题】:Select All checkbox should not select disabled checkbox records angular全选复选框不应选择禁用的复选框记录角度
【发布时间】:2021-04-19 19:10:53
【问题描述】:

有数据表,如果选中全选复选框,需要选择哪些在启用的复选框记录中,并避免禁用记录。我尝试了下面的代码,我无法限制禁用的记录选择。

  checkuncheckall() {
    const totalChecked = this.persons.filter(f => f.checked).length;
    const target = totalChecked !== this.persons.length;
    this.persons.forEach(f => (f.checked = target));
    this.cdRef.detectChanges();
  }

html代码:

<td><input type="checkbox" [disabled]="person.firstName === 'Superman'" class="checkboxCls" [value]="person.checked" [checked]="person.checked" name="id" (change)="person.checked = !person.checked"></td>

Demo

【问题讨论】:

    标签: angular typescript


    【解决方案1】:
    checkuncheckall() {
        //First filter enabled checkbox
        const filteredCheckboxes = this.persons.filter(f => f.firstName !== "Superman");
        const totalChecked = filteredCheckboxes.filter(f => f.checked).length;
        const target = totalChecked !== filteredCheckboxes.length;
        filteredCheckboxesforEach(f => f.checked = target);
        this.cdRef.detectChanges();
      }
    

    【讨论】:

      猜你喜欢
      • 2022-10-13
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2019-06-02
      • 2019-10-15
      • 2020-10-21
      • 1970-01-01
      • 2016-12-07
      相关资源
      最近更新 更多