Home > Software design >  Primeng <p-table> Clear selected checkboxes with Angular
Primeng <p-table> Clear selected checkboxes with Angular

Time:01-29

I am new to Angular and primeng p-table. I am looking for a code snip or reference to know how to clear selected checkboxes to make all checkboxes to be unselected with code in Angular component.ts file when use primeng p-table.

CodePudding user response:

Assuming you have the selectionMode binding set to multiple, the selected data is binded to an array you declared in your component class. All you have to do is make a button “Clear” for example that empties that array.

//html
<p-table> … selectionMode=“multiple” [(selection)]=“selectedObjs” … </p-table>
<button (click)=“clearSelected()”>Clear</button>

//component
selectedObjs: {}[] = [];
…
clearSelected(): void {
this.selectedObjs = [];
}

  • Related