0

I declare a table with paginator in the following way:

<p-table id="tblRequestResponse" name="tblRequestResponse" [value]="requestResponseSummaries" sortField="dateTime" [sortOrder]="-1" lazyLoadOnInit="true"
         [paginator]="true" [pageLinks]="3" [rows]="10" [columns]="cols" selectionMode="single" (onLazyLoad)="loadData($event)" stateStorage="session" stateKey="state-allRequestsandResponses" [lazy]="true" #dt>
  <ng-template pTemplate="header" let-columns>.....

In Code when we were using v4 of the PrimeNG controls I could reset which page was in view by doing something like:

this.dataTable.paginate(3);

now in the current version the paginate method seems to have been dropped with no replacement. How can I manually set the page?

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
bilpor
  • 3,467
  • 6
  • 32
  • 77

1 Answers1

0

You can use first property to manually change current page.

Paginator can also be controlled via model using a binding to the first property where changes trigger a pagination.

Here is an example of how to achieve that:

updatePageNumber() {
    this.first = this.nbRows * (this.pageNumber - 1);
}

See working Stackblitz.

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
  • I can see your example works. mines more complex i dont have an onChangeEvent. My grid has a number of pages. I may be on page 4 and then from one of the records in the grid it links me to the detail of that record. I go to see the detail. Then press the back button on my detail and go back to the grid. By having sessionStorage set as above, the grid comes back in the correct place with pagination set correctly. If however, i order by any of the columns first, then go to say page 4 of the grid, when I come back pagination is set to 1 setting this.dataTable.first doesn't then work. – bilpor Jun 11 '20 at 11:54
  • 1
    It seems to work with `this.dataTable._first = xxxx` where xxxx is the value of first from the page you were initially on before going off to the child record details. I'm accepting this as the answer, because it set me in the right direction. – bilpor Jun 11 '20 at 12:03