我陷入了一个问题,在材料表中,我点击下一个按钮,滚动停留在底部,而它应滚动到顶部。
<mat-table class="table-container" fxFlex="100" [dataSource]="allUsersDataSource">
<ng-container matColumnDef="firstName">
<mat-header-cell fxFlex="25" *matHeaderCellDef> First Name </mat-header-cell>
<mat-cell fxFlex="25" *matCellDef="let element"> {{element.first_name}} </mat-cell>
</ng-container>
<ng-container matColumnDef="lastName">
<mat-header-cell fxFlex="25" *matHeaderCellDef> Last Name </mat-header-cell>
<mat-cell fxFlex="25" *matCellDef="let element"> {{element.last_name}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="allUsersColumns; sticky: true"></mat-header-row>
<mat-row *matRowDef="let row; columns: allUsersColumns;"></mat-row>
</mat-table>
这是背后的代码
onAllUserPaginateChange(event: any){
window.scroll(0,0);
}
任何帮助表示赞赏
我在这里给了一张ID
例如。
<mat-table id ="matTable" class="table-container"
[dataSource]="allUsersDataSource">
<mat-table>
并在typescript文件中该表的paginate方法中。
onAllUserPaginateChange(event: any){
const matTable= document.getElementById('matTable');
matTable.scrollTop = 0;
}