简体   繁体   中英

PrimeNG p-table - Cannot push item (row) into 'selection''

I am using Angular 9, PrimeNG p-table component.

<p-table [value]="cars" selectionMode="multiple" dataKey="id" [(selection)]="selection">

So, what is a problem.

I have 5 rows and for each row I have checkbox. When I select some row or rows, 'selection' is populated and checkboxes are 'checked' but when I manually pust item to 'selection' list - I can't see checked rows until I click on some row checkbox.

Reason why I want to do this is because I have input fields in row/s so when I change input value, I would call a method that will automatically preselect that row as 'checked' in checkbox.

My mistake is that I did push in wrong way

Wrong:
this.selection.push(item);

Good: [...this.selection,item]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM