首页 > 解决方案 > Primeng 复选框上的多行选择和单击行时的单选

问题描述

您好,我需要通过单击复选框进行多项选择,并在单击行后进行单选。你知道我怎样才能在同一张桌子上加入这个吗?

https://www.primefaces.org/primeng/showcase/#/table/selection

标签: angularprimeng

解决方案


您可以使用onRowSelect从选择中删除所有其他内容,但单击的项目除外。

您的 p 表定义将如下所示:

<p-table selectionMode="multiple" [(selection)]="selectedItems" (onRowSelect)="onRowSelect($event) ...> ... </p-table>

和你的功能

onRowSelect(event) {
  this.selectedItems = [event.data];
}

所以复选框使用默认的primeng行为,而行单击取消选择其他所有内容。


推荐阅读