I'm having a problem with jw-angular-pagination. I was adding custom sort function when I found that I have no control over the page of pagination. I wonder how to change selected page to first after sorting?
My code (simplified):
HTML:
<div *ngFor="let result of pageOfItems">
// ...
</div>
<jw-pagination class="fadeIn" [items]="affiliates" (changePage)="onChangePage($event)" [pageSize]="pageSize"></jw-pagination>
TS:
affiliates: any[]; // Let's say there are data already
pageOfItemsAffiliates: any;
pageSize = 10;
currentPage = 1;
constructor() {}
onChangePageAffiliates(pageOfItems: Array<any>) {
this.pageOfItemsAffiliates = pageOfItems;
}
onClickSort(by: string) {
this.affiliates = this.affiliates.sort((a, b) => {
return a.totalBalance > b.totalBalance ? -1 : 1;
});
this.pageOfItemsAffiliates = this.affiliates.slice(0, this.pageSize);
this.currentPage = 1;
}
So when I click page 2, then sort, it will show first 10 elements sorted but jw-pagination widget will still be showing page 2 as active (while the truth is it's showing the first page). How to make it work properly?