我有一个带有分页选项的项目。https://stackblitz.com/edit/angular-sjp8qq
但mat-pagination标签的属性与应用程序逻辑没有关联。谁能告诉我为什么吗?
发布于 2019-06-25 22:45:13
下面是我如何得到一个垫子分页工作在我正在工作的应用程序,以适应您的代码,希望这有帮助。
JS
totalElements = 20;
elementsPerPage = 5;
currentPage = 1;
pageSizeOptions = [5, 10, 20];
fillDataSource() {
this.arraySource = []; // clear so we can repopulate
for ( let i = 0; i < this.arraySize; i++) {
if (this.elementsPerPage && this.currentPage) {
if (i > (this.elementsPerPage * (this.currentPage - 1)) && i <= (this.elementsPerPage * (this.currentPage))) {
this.arraySource.push(this.arrayTemplate)
}
}
}
this.data = new MatTableDataSource(this.arraySource)
}
onChangedPage(pageData: PageEvent) {
this.currentPage = (pageData.pageIndex + 1);
this.projectsPerPage = pageData.pageSize;
this.fillDataSource();
} <mat-paginator
#paginator
[length]="totalElements"
[showFirstLastButtons]="true"
[pageSizeOptions]="pageSizeOptions"
[pageSize]="elementsPerPage"
(click)="onChangedPage($event)">
</mat-paginator>https://stackoverflow.com/questions/56762101
复制相似问题