如何在 Ngx-databletable 中只选中 1 个复选框?

How to only have selected 1 checkbox in a Ngx-datable table?

我有一个 ngx-datatable 复选框,一次只需要选择 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> 

但是事件只包含选中的内容。是否可以取消选择除最后一个复选框外的所有选择?

泳道提供了一个关于如何清除所有选择的示例here with a demo 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);
  }


}