当我在表格和表格之间切换时,材料表分页被禁用。没有错误被抛出,当我刷新它的启用时。我已经尽力了。请帮我解决这个问题
物料表代码 ts 代码
displayedColumns: string[] = ['Receptionist', 'Slot', 'Status', 'Timing', 'Action'];
dataSource: MatTableDataSource<any>;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
this.authService.getReceptionistList(data).subscribe((recep) => {
if (recep.status) {
this.receptionLists = recep.receptionist;
for (let i = 0; i < Object.keys(this.receptionLists).length; i++) {
this.recepList.push(this.receptionLists[i]);
this.dataSource = new MatTableDataSource(this.recepList);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.filteredDataLength = this.dataSource.filteredData.length;
}
}
});
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="Receptionist">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Receptionist </th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<ng-container matColumnDef="Slot">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Slot</th>
<td mat-cell *matCellDef="let row">shift1 </td>
</ng-container>
<ng-container matColumnDef="Status">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let row"> {{row.status == 1 ? 'active': 'inactive'}} </td>
</ng-container>
<ng-container matColumnDef="Timing">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Timing </th>
<td mat-cell *matCellDef="let row"> {{row.timings[0]['monday']['shift1'].start_time}} : {{row.timings[0]['monday']['shift1'].end_time}} </td>
<!-- <td mat-cell *matCellDef="let row">12:00 PM - 14:00 PM</td>-->
</ng-container>
<ng-container matColumnDef="Action">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Action </th>
<td mat-cell *matCellDef="let row ">
<div class="btn btn-group">
<button mat-icon-button color="primary" (click)="editDeskUserClick(row.user_id)"><i class="fas fa-pencil-alt pointer"></i></button>
<button mat-icon-button color="warn" (click)="deleteDeskUser(row.user_id)"><i class="fas fa-trash"></i></button>
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;">
</tr>
</table>
<mat-paginator [pageSizeOptions]="[7, 14, 21, 100]" showFirstLastButtons ></mat-paginator>
</div>