Skip to content

[Paginator] numberOfPages is off by one #10699

@haochi

Description

@haochi

Bug, feature request, or proposal:

Bug: numberOfPages is off by one.

Right now numberOfPages() is calculated as

Math.ceil(this.length / this.pageSize) - 1;

Which would work nicely for zero-based calculations, but doesn't work so well for actual display or the mental model of what "number of pages" represent.

For example:

  • length=1, pageSize=5 => numberOfPages() returns 0 (there should be 1 page right?)

Consider the example of splitting an array into page chunks (i.e. any[] => any[][]), the resulting array be size of 1.

What is the expected behavior?

Should return the current page count.

What is the current behavior?

As described above.

What is the use-case or motivation for changing an existing behavior?

See above.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

since v5.2.0, also in the v6.0.0-rc.0

Is there anything else we should know?

There doesn't seem to be any tests for numberOfPages, a public method.

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions