3

I need to automatically navigate through the pages when the maximum rows number per page is reached.

I have a dataTable and an array that are the records. I added two items into my array and defined the property [rows] as 1.

.html

<p-dataTable #dt [value]="cars" [rows]="1" [paginator]="true"></p-dataTable>

.ts

this.cars.push(new Car("A", "B", "C", "D"));
this.cars.push(new Car("E", "F", "G", "H"));  

Also, did the following code when adding a new car when clicking on a button:

.ts

@ViewChild('dt') data: DataTable;

// before this line is all the logic to add the car in the list
if ((this.cars.length - 1) %  this.data.rows === 0) {
  this.data.paginate();
}

When the first row of a new page is added, it executes the paginate but nothing happens.

What can I do?

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
icestorm
  • 65
  • 5
  • which version of angular and primeng are you using? and why are you calling paginate() manually? – Niladri Apr 03 '18 at 07:21
  • I am using the version 5.0.3 and primeng 5.2.3. Because when I add a new record that creates a new page of rows I want the table to paginate automatically to the new page. For example: my table supports 10 rows per page, when I add the 11th row, it will create a new page and I want the table to go directly to this new page, not stay in the current. – icestorm Apr 03 '18 at 10:53

0 Answers0