【发布时间】:2022-05-15 08:01:49
【问题描述】:
当我点击表格标题中的复选框时。然后应该检查表中的所有复选框。目前,我正在使用 angular 12 和 primeNG 表。
<p-table styleClass="text-sm" [value]="value" [loading]="loading" [rowHover]="true" [scrollable]="true" scrollDirection="both" class="p-element p-datatable-gridlines" (onLazyLoad)="onLazyLoad.emit($event)" [ngClass]="{'p-datatable-is-loading': loading}"
[paginator]="true" [rows]="10" [showCurrentPageReport]="true" responsiveLayout="scroll"
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} entries" [rowsPerPageOptions]="[10,20,30]"
onPage="handlePageChange($event)">
<ng-template pTemplate="header">
<tr>
///////////////////// HERE THE CHECKBOX IN TABLE HEARDER///////////////////////////////
<th *ngIf="status!='all'" style="width: 40px" pFrozenColumn class="border-right-none">
<p-checkbox value="{{value.id}}" [(ngModel)]="selectedLeaves" (onChange)="allSelect(value)"></p-checkbox>
</th>
<th *ngIf="state!=_componentState.VIEW" style="width: 30px" pFrozenColumn class="border-right-none"></th>
<th style="width: calc(358px / 2)" pFrozenColumn class="border-left-none">From</th>
<th style="width: calc(358px / 2)" pFrozenColumn class="p-frozen-column-last border-right-none">To</th>
<th style="width: 180px">Department</th>
<th pSortableColumn="created_at" style="width: 100px">Date Field<p-sortIcon field="created_at"></p-sortIcon></th>
<th style="width: 100px" class="border-left-none">Day</th>
<th style="width: 180px">Employee Name</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-leave let-rowIndex="rowIndex">
<tr [class]="{'passed-date': helper.isPassedCurrentDate(leave.leave_from)}" (dblclick)="handleDblClickRow(leave)">
///////////////////// HERE THE CHECKBOX IN TABLE DETAILS///////////////////////////////
<td *ngIf="status!='all'" style="width: 40px" pFrozenColumn class="border-right-none">
<div *ngIf="status!='all'">
<p-checkbox name="group1" value="{{leave.id}}" [(ngModel)]="selectedLeaves" inputId="ch"></p-checkbox>
</div>
</td>
<td *ngIf="state!=_componentState.VIEW" style="width: 30px" pFrozenColumn class="border-right-none">
<div *ngIf="state==_componentState.ALL">
<div class="{{leave.status}}-dot"></div>
</div>
</td>
<td style="width: calc(358px / 2)" pFrozenColumn class="border-left-none">{{helper.formatDate(leave.leave_from, 'MMM D, YYYY HH:mm', false)}}</td>
<td style="width: calc(358px / 2)" pFrozenColumn class="p-frozen-column-last border-right-none">{{helper.formatDate(leave.leave_to, 'MMM D, YYYY HH:mm', false)}}</td>
<td style="width: 180px"></td>
<td style="width: 100px" class="border-left-none">{{helper.formatDate(leave.created_at, 'MM/DD')}}</td>
<td style="width: 100px">{{helper.formatDate(leave.created_at, 'ddd')}}</td>
<td style="width: 180px" class="text-capitalize">{{leave.employee_name}}</td>
</tr>
</ng-template>
我想用这个方法allSelect(value)
例如,当我单击桌面复选框时,应自动选中所有复选框。我不想使用primeNG table 选择。
https://stackblitz.com/edit/primeng-tableselection-demo你可以从这个例子中查看
【问题讨论】:
标签: javascript angular typescript primeng