primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.19k stars 4.55k forks source link

Table: Flawed example in paginator documentation #16308

Closed Wendelstein7 closed 6 days ago

Wendelstein7 commented 2 weeks ago

This issue is created to accompany a pull request fixing the bug.

Describe the bug

The example code for programmatically paginating trough tables, in the isLastPage() function, is flawed because it only works correctly when the amount of items in the table is an exact multiple of the rows per page count.

The issue can be fixed by replacing

return this.customers ? this.first === this.customers.length - this.rows : true;

with

return this.customers ? this.first + this.rows >= this.customers.length : true;

Environment

Reproducer

No response

Angular version

18.1.0

PrimeNG version

17.18.9

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

22.6.0

Browser(s)

No response

Steps to reproduce the behavior

Implement the example provided on [https://primeng.org/table#paginator], and make sure that the count of items (customers in the example) is not a multiple of the row size. This will result in the isLastPage() never returning true.

Expected behavior

The isLastPage() should return true when on the last page of a paginated table.

Wendelstein7 commented 2 weeks ago

I submitted the pull request fixing this issue.