如何仅在Ngx表格中选中1个复选框?

问题描述

我有一个ngx数据表女巫复选框,一次只能选择1个复选框。

我尝试使用以下方法访问该事件:

html

 <ngx-datatable 
  class="margin-left bootstrap" 
  [rows]="rows" 
  [loadingIndicator]="'true'" 
  [rowHeight]="'30'"
  [reorderable]="'true'" 
  [scrollbarH]="'true'" 
  [columnMode]="'standard'" 
  [columns]="columns"
  [selectionType]="'checkBox'"
  [selectAllRowsOnPage]="false"
  (select)='onSelect($event)'>    
  </ngx-datatable> 

但是该事件仅包含所选内容。除了最后单击的复选框,是否有办法取消所有选择?

解决方法

Swimlane提供了有关如何使用演示here清除所有选择here的示例。请注意页面顶部的“删除”按钮。

要点是利用@Inputs [selected]和更新@Output (select)

component.html

 <ngx-datatable 
  class="margin-left bootstrap" 
  [rows]="rows" 
  [loadingIndicator]="'true'" 
  [rowHeight]="'30'"
  [reorderable]="'true'" 
  [scrollbarH]="'true'" 
  [columnMode]="'standard'" 
  [columns]="columns"
  [selectionType]="'checkbox'"
  [selectAllRowsOnPage]="false"
  (select)='onSelect($event)'>    
  </ngx-datatable> 

component.ts

export class MyComponent {

  selected = [];


  onSelect({ selected }) {
    this.selected = [];
    this.selected.push(...selected);
  }


}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...