Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Pagination): added optional offset prop #3383

Merged
merged 2 commits into from
Dec 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export interface PaginationProps extends React.HTMLProps<HTMLDivElement> {
firstPage?: number;
/** Current page number. */
page?: number;
/** Start index of rows to display, used in place of providing page */
offset?: number;
/** First index of items on current page. */
itemsStart?: number;
/** Last index of items on current page. */
Expand Down Expand Up @@ -140,7 +142,8 @@ const Pagination: React.FunctionComponent<PaginationProps & InjectedOuiaProps> =
paginationTitle: 'Pagination'
},
firstPage = 1,
page = 1,
page = 0,
offset = 0,
defaultToFullPage = false,
itemCount,
itemsStart = null,
Expand All @@ -160,8 +163,12 @@ const Pagination: React.FunctionComponent<PaginationProps & InjectedOuiaProps> =
ouiaId = null,
...props
}: PaginationProps & InjectedOuiaProps) => {
if (!page && offset) {
page = Math.ceil(offset / perPage);
}

const lastPage = Math.ceil(itemCount / perPage) || 0;
if (page < firstPage) {
if (page < firstPage && itemCount > 0) {
page = firstPage;
} else if (page > lastPage) {
page = lastPage;
Expand Down