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.
5 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));
}

- 437
- 3
- 7
-
Thank you, this works. I just had to set setTimeout(() => { this._paginator.changePage(this.musicianService.page) }, 0); to get it work. – keschra Jun 01 '20 at 11:13
-
I ended up using the ```this.paginator.changePageToFirst(null);``` in order to reset the page index when updating the filters (note: this does call ```changePage(0)``` in the source). – Ashitakalax Jul 30 '21 at 19:30
-
Yeah this works thanks. Theres some weird timing sync problem with the component itself which is annoying so we have to use that setTimeout – Andrew Howard Nov 05 '22 at 17:25
The first property is the best option to define the current page of the pager provided by the Primeng.
first = (page-1) * rows;
In template,
<p-paginator
[rows]="10"
[totalRecords]="120"
[rowsPerPageOptions]="[10, 20, 30]"
[first]="first"
></p-paginator>
In component,
pageSize = 10;
currentpage = 2;
first;
ngOnInit() {
this.first = (this.currentpage-1)* this.pageSize;
}
It will successfully set the active page without using setTimeout.

- 51
- 1
- 2
-
3Ty :) ! IMO the paginator component should handle this calc for you... we should just have to give the desired page in Input – Adrien SAULNIER Oct 10 '22 at 14:19
-
Thanks so much for this, this stumped me. It’s so silly we have to work this out. Also if you want to reset the paginator to page 1 (after initial page render), you still have to use the above approved answer using viewChild. The paginator looks great but it’s a bit clunky – Andrew Howard Dec 15 '22 at 09:53
If you have a listing component as a child component then you can keep the value of the Pagination event.first in the parent component and pass it back to the child component something like this.
@Input() paginationFirstValue: number = 0;
<p-paginator
#paginator
[first]="paginationFirstValue"
[rows]="10"
selectionMode="single"
[alwaysShow]="false"
[totalRecords]="dataObj.total"
(onPageChange)="paginate($event)"
></p-paginator>
And emit the event to the parent
paginate(event: Pagination): void {
this.paginationFirstValue = event.first;
this.pageChange.next(event);
}

- 1
- 2
The paginator current page is managed using the first property. First property must contain the index of the first row displayed. You can automate this using the Event.first from the event handler: onPageChange($event)
Solution: In view, create a paginator:
<p-paginator [rows]="paginatorPageSize" [totalRecords]="paginatorTotalRecords" (onPageChange)="paginate($event)"
[first]="paginatorFirstRecordIndex"></p-paginator>
// controller change
paginate($event) {
...
this.paginatorFirstRecordIndex=$event.first

- 720
- 7
- 13
I saw that the topic is older but I was having a similar problem and if someone ever needs it... In my case, I was using the event returned from the onPageChange()
function in the wrong way, I was assigning to my variable [first]
the value of ev.page
and actually I wanted ev.first
component.html:
<p-paginator (onPageChange)="onPageChange($event)" [first]="pokemonsFirst"
[rows]="pokemonsPerPage" [totalRecords]="pokemonsCount" [showJumpToPageDropdown]="true" [showPageLinks]="false">
</p-paginator>
component.ts:
onPageChange(e: any) {
this.pokemonsPage = e.page;
this.pokemonsFirst = e.first;
// my request here
}

- 11,310
- 7
- 18
- 42

- 21
- 1