Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 8be7509

Browse files
committed
prevent blank page at the end of pagination
1 parent 45928b0 commit 8be7509

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/dash-table/derived/data/viewport.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { memoizeOneFactory } from 'core/memoizer';
2+
import { lastPage } from 'dash-table/derived/paginator';
23

34
import {
45
Data,
@@ -13,10 +14,7 @@ function getNoPagination(data: Data, indices: Indices): IDerivedData {
1314
}
1415

1516
function getFrontEndPagination(settings: IPaginationSettings, data: Data, indices: Indices): IDerivedData {
16-
let currentPage = Math.min(
17-
settings.current_page,
18-
Math.floor(data.length / settings.page_size)
19-
);
17+
let currentPage = Math.min(settings.current_page, lastPage(data, settings));
2018

2119
const firstIndex = settings.page_size * currentPage;
2220
const lastIndex = Math.min(

src/dash-table/derived/paginator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export interface IPaginator {
1616
loadPrevious(): void;
1717
}
1818

19+
export function lastPage(data: Data, settings: IPaginationSettings) {
20+
return Math.max(Math.ceil(data.length / settings.page_size) - 1, 0);
21+
}
22+
1923
function getBackEndPagination(
2024
pagination_settings: IPaginationSettings,
2125
setProps: SetProps
@@ -43,7 +47,7 @@ function getFrontEndPagination(
4347
) {
4448
return {
4549
loadNext: () => {
46-
let maxPageIndex = Math.floor(data.length / pagination_settings.page_size);
50+
const maxPageIndex = lastPage(data, pagination_settings);
4751

4852
if (pagination_settings.current_page >= maxPageIndex) {
4953
return;

0 commit comments

Comments
 (0)