Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeNG Paginator set Page

I'm using the primeng paginator component inside an Angular 9 Project to page a huge list of profiles. If a user is on page 3, opens a profile and returns to search, the current page is 1, but it should be 3. I have saved the page inside a service, so the right data is shown, but the paginator is showing the wrong page. I could not find a way to set the current page of the paginator. Using the [first] attribute is not working.

like image 929
keschra Avatar asked Jan 23 '26 01:01

keschra


1 Answers

You need to set the page manually. You can use Angular @ViewChild decorator to get access to PrimeNg Paginator component.

Give an id to that paginator in template:

<p-paginator #paginator ...></p-paginator>

And use it in component:

import { Paginator } from 'primeng/paginator';


@ViewChild('paginator', { static: true }) paginator: Paginator

private updateCurrentPage(currentPage: number): void {
  setTimeout(() => this.paginator.changePage(currentPage));
}
like image 199
shumih Avatar answered Jan 25 '26 17:01

shumih



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!