我一直在尝试对不使用mat-table的结果列表执行mat-pagination。但是,我在这里找到的所有示例都使用带有分页功能的mat-table。
感谢您对此的帮助。
我目前正在onInit上从解析程序获取所有数据,并且不需要每次用户与分页进行交互时都从后端获取数据。
component.html
<div class="axi-results-wrapper">
<mat-accordion>
<ng-container *ngFor="let process of Processes; let i = index;">
<mat-expansion-panel (opened)="setOpened(i)"
(closed)="setClosed(i)" hideToggle="true">
<mat-expansion-panel-header [collapsedHeight]="'66px'" [expandedHeight]="'60px'">
<div *ngIf="currentlyOpenedItemIndex !== i" class="row axi-results-row">
<span class="col-md-4 axi-results-row__txt">
<div class = "axi-result-circle axi-result-circle--bg-color">
<i class="far fa-copy"></i>
</div>
<div class="axi-results-row__txt axi-results-row__txt--primary">{{process.name}}</div>
</span>
<span class="col-md-3 axi-results-row__txt axi-results-row__txt--secondary">{{process.repoUrl}}</span>
<span class="col-md-3 axi-results-row__txt axi-results-row__txt--secondary">{{process.processType}}</span>
<span class="col-md-2 axi-results-row__txt axi-results-row__icon" *appHasAccess="roleTitle">
<span (click)="editProcess(process, i); $event.stopPropagation();">
<i class="material-icons">edit</i>
</span>
<span (click)="deleteProcess(process.id, i); $event.stopPropagation()">
<i class="material-icons">delete_outline</i>
</span>
</span>
</div>
<div *ngIf="currentlyOpenedItemIndex === i">
<app-result-header [iconType]="type" [headerName]="process.name" (editData)="editProcess(process, i)" (deleteFunc)="deleteProcess(process.id, i)"></app-result-header>
</div>
</mat-expansion-panel-header>
<app-process-detail-view [process]="process"></app-process-detail-view>
</mat-expansion-panel>
</ng-container>
</mat-accordion>
<mat-paginator [length]="length"
[pageIndex]="pageIndex"
[pageSize]="pageSize"
[pageSizeOptions]="[5, 10, 25, 100]">
</mat-paginator>
</div>
component.ts
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
constructor(private actr: ActivatedRoute) { }
ngOnInit() {
this.getProcessService();
}
getProcessService() {
// Getting all the data fetched from the active route
this.actr.data.subscribe((res) => {
this.Processes = res.process;
});
}
答案 0 :(得分:1)
mat-paginator和其他组件一样,具有inputs
和outputs
。您可以使用[name of property]
控制输入,并使用(name of output)="yourFunction($event)"
请参见docs
例如,您可以使用
<mat-paginator [length]="length"
[pageSize]="pageSize"
[pageSizeOptions]="pageSizeOptions"
(page)="change($event)">
</mat-paginator>
change(event:PageEvent)
{
//make something
console.log(event.length);
console.log(event.pageIndex);
console.log(event.pageSize);
console.log(event.previousPageIndex)
//possible call to a function in a service to get data from one index to another one
this.obs$=this.data.service.getItems(event.previousPageIndex*event.pageSize,
event.PageIndex*event.pageSize
)
}