- Notifications
You must be signed in to change notification settings - Fork 431
Implement Pagination #138
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
Implement Pagination #138
Conversation
package.json Outdated
| "prop-types": "^15.5.10", | ||
| "react": "^15.6.1", | ||
| "react-dom": "^15.6.1" | ||
| "react": "^16.0.0", |
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.
package.json Outdated
| "react": "^15.0.0", | ||
| "react-dom": "^15.0.0" | ||
| "react": "^15.0.0 || ^16", | ||
| "react-dom": "^15.0.0 || ^16" |
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.
I'll consider to make ^16 only as peer when we release, but I need some test
| text: 'Product Price' | ||
| }]; | ||
| <BootstrapTable keyField='id' data={ products } columns={ columns } /> |
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.
forget to update code
| text: 'Product Price' | ||
| }]; | ||
| <BootstrapTable keyField='id' data={ products } columns={ columns } /> |
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.
forgot to update code
| @@ -0,0 +1,134 @@ | |||
| /* eslint no-mixed-operators: 0 */ | |||
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 class is main class for calculate page information by props
| componentWillReceiveProps(nextProps) { | ||
| const { dataSize, currSizePerPage } = nextProps; | ||
| | ||
| if (currSizePerPage !== this.props.currSizePerPage || dataSize !== this.props.dataSize) { |
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.
currSizePerPage and dataSize will effect on totalPages and lastPage
| data: store.getByCurrPage(currPage, currSizePerPage) | ||
| }); | ||
| | ||
| return [ |
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.
there's a kind of different than previous wrapper,
-
In this class, I export a factory function instead of HoC(this factory function will create a HoC)
-
This factory function will have two args:
baseElementandConstwhich are passed fromreact-bootstrap-table2(table-factory) -
This HOC component is not render next element, instead, I render
baseelement and Pagination component together
| const base = baseElement({ | ||
| ...this.props, | ||
| key: 'table', | ||
| data: store.getByCurrPage(currPage, currSizePerPage) |
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.
slice data by page here
| } else if (this.props.columns.filter(col => col.sort).length > 0) { | ||
| return wrapWithSort(baseProps); | ||
| } else if (this.props.pagination) { | ||
| return wrapWithPagination(baseProps); |
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.
use wrapper as usual
| if (props.pagination) { | ||
| const { wrapper } = props.pagination; | ||
| const PaginationBase = wrapper(pureTable, Const); | ||
| return React.createElement(PaginationBase, { ...props }); |
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.
- get pagination
wrapperfrom props - call the wrapper function (
wrapperis a factory function)
7c1964c to e2313d8 Compare e2313d8 to f0ff30d Compare | <BootstrapTable keyField='id' data={ products } columns={ columns } pagination={ paginator } /> | ||
| `; | ||
| | ||
| class BasicPaginationTable extends React.PureComponent { |
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.
I just wondered what kind of difficulties you faced and you selected PureComponent here :)?
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.
Nothing there, I just test some state change manually but forgot to remove it, thanks this reminder
| umm.... huge PR, review by commit will be little better lol. |
d5d2da5 to 3ece5ff Compare 3ece5ff to ec5e78a Compare | @Chun-MingChen after merged, you are suppose to run |
#135