admin管理员组文章数量:1323224
I am using primeng p-table
and using the checkbox selector for selecting the rows as follows.
<p-table [value]="data" [paginator]="true" [loading]="loading" [(selection)]="selectedItems" #dt>
<ng-template pTemplate="header">
<tr>
<th style="width: 3rem">
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
</th>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-row>
<td>
<p-tableCheckbox [value]="row"></p-tableCheckbox>
</td>
<td>Column 1</td>
<td>Column 2</td>
</ng-template>
</p-table>
This is working an I am able to select the rows by clicking on the checkbox. But I need to have the following things also.
- Select the row by clicking anywhere on the row(also tick the checkbox)
- Highlight the selected row.
I have checked other options for selecting the rows like Multiple Selection without MetaKey, but it doesn't have a Select All option.
How can I do this ? Any help will be appreciated. Thanks
I am using primeng p-table
and using the checkbox selector for selecting the rows as follows.
<p-table [value]="data" [paginator]="true" [loading]="loading" [(selection)]="selectedItems" #dt>
<ng-template pTemplate="header">
<tr>
<th style="width: 3rem">
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
</th>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-row>
<td>
<p-tableCheckbox [value]="row"></p-tableCheckbox>
</td>
<td>Column 1</td>
<td>Column 2</td>
</ng-template>
</p-table>
This is working an I am able to select the rows by clicking on the checkbox. But I need to have the following things also.
- Select the row by clicking anywhere on the row(also tick the checkbox)
- Highlight the selected row.
I have checked other options for selecting the rows like Multiple Selection without MetaKey, but it doesn't have a Select All option.
How can I do this ? Any help will be appreciated. Thanks
Share Improve this question asked Sep 30, 2020 at 5:57 Happy CoderHappy Coder 4,70215 gold badges87 silver badges179 bronze badges1 Answer
Reset to default 4This is taken straight from the primeng documentation. Your row is not well formed, you are missing a wrapping "tr" under the body template. You basically need to set the selection mode and the selectable row attribute, and that should highlight the row. You can add some logic in the code for marking the checkbox as selected based on selectedCar in the example below.
<p-table [columns]="cols" [value]="cars" selectionMode="single" [(selection)]="selectedCar">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
本文标签: javascriptHighlight selected row in primeng tableStack Overflow
版权声明:本文标题:javascript - Highlight selected row in primeng table - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742075923a2419408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论