VariableTao
VariableTao

Reputation: 171

Primeng <p-table> Clear selected checkboxes with Angular

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.

Upvotes: 0

Views: 798

Answers (1)

KennySchl
KennySchl

Reputation: 61

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 = [];
}

Upvotes: 1

Related Questions