重置分页器第一页 angular material
reset paginator first page angular material
我正在尝试转到 mat-paginator 的第一页,即重置分页,但它不起作用。知道如何解决吗?
我的html是这样的
<mat-paginator [length]="itemTotal" [pageIndex]="page" [pageSize]="itemPage" (page)="pageEvent = getPublicationFollowersData($event)">
</mat-paginator>
打字稿:
getPublicationFollowersData(event?: PageEvent) {
this.getPublicationsUser(event.pageIndex);
}
我尝试用以下方法初始化页面:
this.page = 1
但是不行。
您需要使用 ViewChild
装饰器来 select 分页器,然后设置分页器的 pageIndex
属性。
@ViewChild() paginator: MatPaginator;
...
this.paginator.pageIndex = 0;
编辑:根据其他答案的建议,如果您想将分页器重置为第一页,最好使用 this.paginator.firstPage()
<mat-paginator #paginator [length]="length"
[pageSize]="pageSize"
[pageSizeOptions]="pageSizeOptions"
(page)="pageEvent = paginationClicked($event)">
</mat-paginator>
@ViewChild('paginator') paginator: MatPaginator;
this.paginator.firstPage();
为 material angular 分页器和数据源创建引用
dataSource: MatTableDataSource<any>;
@ViewChild(MatPaginator) paginator: MatPaginator;
您想使用以下代码重置分页器
this.dataSource.paginator = this.paginator;
也可以通过调用paginator的首页方法重置
this.paginator.firstPage();
如果使用
@ViewChild(MatPaginator, { static : true} ) paginator: MatPaginator;
应该是
@ViewChild(MatPaginator, { static : false} ) paginator: MatPaginator;
如果static:true分页器对象未定义。
我正在尝试转到 mat-paginator 的第一页,即重置分页,但它不起作用。知道如何解决吗?
我的html是这样的
<mat-paginator [length]="itemTotal" [pageIndex]="page" [pageSize]="itemPage" (page)="pageEvent = getPublicationFollowersData($event)">
</mat-paginator>
打字稿:
getPublicationFollowersData(event?: PageEvent) {
this.getPublicationsUser(event.pageIndex);
}
我尝试用以下方法初始化页面:
this.page = 1
但是不行。
您需要使用 ViewChild
装饰器来 select 分页器,然后设置分页器的 pageIndex
属性。
@ViewChild() paginator: MatPaginator;
...
this.paginator.pageIndex = 0;
编辑:根据其他答案的建议,如果您想将分页器重置为第一页,最好使用 this.paginator.firstPage()
<mat-paginator #paginator [length]="length"
[pageSize]="pageSize"
[pageSizeOptions]="pageSizeOptions"
(page)="pageEvent = paginationClicked($event)">
</mat-paginator>
@ViewChild('paginator') paginator: MatPaginator;
this.paginator.firstPage();
为 material angular 分页器和数据源创建引用
dataSource: MatTableDataSource<any>;
@ViewChild(MatPaginator) paginator: MatPaginator;
您想使用以下代码重置分页器
this.dataSource.paginator = this.paginator;
也可以通过调用paginator的首页方法重置
this.paginator.firstPage();
如果使用
@ViewChild(MatPaginator, { static : true} ) paginator: MatPaginator;
应该是
@ViewChild(MatPaginator, { static : false} ) paginator: MatPaginator;
如果static:true分页器对象未定义。