I am struggling with this. I have two separate p-paginator components in my angular component. I want to make them sync with each other. So, if I click on any of these, the other should also be updated.
I tried to fire the changePage() event for the paginator(that hasn't changed) when the user change the other one and vice versa, hoping to make them synchronize but that didn't end well as it formed an infinite loop.
Any help regarding would be highly appreciated. Thanks
@ViewChild('paginatorTop', { static: true }) paginatorTop: Paginator;
@ViewChild('paginatorBottom', { static: true }) paginatorBottom: Paginator;
onTopPageChange(e) {
this.filter.pageNo = e.page + 1;
this.getProducts();
}
onBottomPageChange(e) {
this.paginatorTop.changePage(e.page);
this.filter.pageNo = e.page + 1;
this.getProducts();
}
<!-- paginator 1 -->
<p-paginator #paginatorTop [rows]="perRow" showCurrentPageReport="true"
currentPageReportTemplate="Showing {currentPage} of {totalPages}" (onPageChange)="onTopPageChange($event)"
[totalRecords]="total" styleClass="pr-0">
</p-paginator>
<!-- Dynamic data coming from an API -->
<p-paginator #paginatorBottom [rows]="perRow" showCurrentPageReport="true"
currentPageReportTemplate="Showing {currentPage} of {totalPages}" (onPageChange)="onBottomPageChange($event)"
[totalRecords]="total" styleClass="pr-0">
</p-paginator>