-
Notifications
You must be signed in to change notification settings - Fork 380
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(react-grid): Ability to show all rows on a page via page size selector #150
Changes from 7 commits
a17b457
d5d6e1f
206974c
3e44ddf
8f68556
ae44b8f
600419f
d8dcb8b
0742bb6
333cad0
38edd54
4d768a9
777f7d7
9ebb721
4379934
93c4387
6e41a41
497475c
a4b9a62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
export const paginate = (rows, pageSize, page) => | ||
rows.slice(pageSize * page, pageSize * (page + 1)); | ||
const ALL_PAGES_TITLE = 'All'; | ||
|
||
export const paginate = (rows, pageSize, page) => ( | ||
pageSize ? | ||
rows.slice(pageSize * page, pageSize * (page + 1)) : | ||
rows | ||
); | ||
|
||
export const ensurePageHeaders = (rows, pageSize) => { | ||
const result = rows.slice(); | ||
if (!pageSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why could we not escape earlier? Slicing seems redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slicing is for array copying, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but this copy is needed only for processing listed below in this function. We can return original rows if processing is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, got it. |
||
return result; | ||
} | ||
|
||
const headers = []; | ||
let currentIndex = 0; | ||
|
@@ -27,13 +35,24 @@ export const ensurePageHeaders = (rows, pageSize) => { | |
return result; | ||
}; | ||
|
||
export const totalPageCount = (rows, pageSize) => Math.ceil(rows.length / pageSize); | ||
export const totalPageCount = (rows, pageSize) => ( | ||
pageSize ? Math.ceil(rows.length / pageSize) : 1 | ||
); | ||
|
||
export const totalCount = rows => rows.length; | ||
|
||
export const firstRowOnPage = (currentPage, pageSize) => (currentPage * pageSize) + 1; | ||
export const firstRowOnPage = (currentPage, pageSize) => ( | ||
pageSize ? (currentPage * pageSize) + 1 : 1 | ||
); | ||
|
||
export const lastRowOnPage = (currentPage, pageSize, totalRowCount) => { | ||
const index = (currentPage + 1) * pageSize; | ||
return index > totalRowCount ? totalRowCount : index; | ||
let result = totalRowCount; | ||
if (pageSize) { | ||
const index = (currentPage + 1) * pageSize; | ||
result = index > totalRowCount ? totalRowCount : index; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
export const pageSizeTitle = pageSize => pageSize || ALL_PAGES_TITLE; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ totalCount | number | | Specifies the total rows count | |
currentPage | number | | Specifies the current page number | ||
defaultCurrentPage | number | 0 | Specifies the initial current page for the uncontrolled mode | ||
onCurrentPageChange | (currentPage: number) => void | | Handles current page changes | ||
pageSize | number | | Specifies the page size | ||
pageSize | number | | | Specifies the page size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, remove redundant |
||
defaultPageSize | number | 10 | Specifies the initial page size for the uncontrolled mode | ||
onPageSizeChange | (pageSize: number) => void | | Handles page size changes | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This const seems unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used here
export const pageSizeTitle = pageSize => pageSize || ALL_PAGES_TITLE;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
pageSizeTitle
export is strange, isn't it? It has a localizable string that can't be configured by a user.