I'm using PrimeNG and Angular 14. I have a checkbox in my p-table
<p-tableCheckbox (click)="onSelectAll($event)"></p-tableCheckbox>
I would like to know if the state of the box is checked or unchecked. So I tried
onSelectAll(event: any) { if (event.checked) { this.selectedCustomers = this.customers.slice(); // select all } else { this.selectedCustomers = []; // unselect all } }
but "event.checked" is repeatedly undefined. I also tried "event.target.checked" but to no avail. How do I tell if my checkbox is checked or not?
You should to use these three events on p-table
tag itself not on p-tableCheckbox
<p-table
(onRowSelect)="pass your function here"
(onRowUnselect)="pass your function here"
(onHeaderCheckboxToggle)="pass your function here"
don't forget to add selection array for your rows
[(selection)]="selectionRowsArr"
event.data
event.data
event.checked
you can check this link: check table event and type of selection tabels