diff --git a/packages/react-bootstrap-table2-paginator/src/index.js b/packages/react-bootstrap-table2-paginator/src/index.js
index c74c016b4..375f1fabc 100644
--- a/packages/react-bootstrap-table2-paginator/src/index.js
+++ b/packages/react-bootstrap-table2-paginator/src/index.js
@@ -1,8 +1,6 @@
-import Pagination from './pagination';
-import wrapper from './wrapper';
+import PaginationWrapper from './wrapper';
export default (options = {}) => ({
- Pagination,
- wrapper,
+ PaginationWrapper,
options
});
diff --git a/packages/react-bootstrap-table2-paginator/src/wrapper.js b/packages/react-bootstrap-table2-paginator/src/wrapper.js
index 349e7a83c..94995cd63 100644
--- a/packages/react-bootstrap-table2-paginator/src/wrapper.js
+++ b/packages/react-bootstrap-table2-paginator/src/wrapper.js
@@ -5,135 +5,152 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Const from './const';
+import Pagination from './pagination';
import { getByCurrPage } from './page';
-const wrapperFactory = baseElement =>
- class PaginationWrapper extends Component {
- static propTypes = {
- store: PropTypes.object.isRequired
+class PaginationWrapper extends Component {
+ static propTypes = {
+ store: PropTypes.object.isRequired,
+ baseElement: PropTypes.func.isRequired
+ }
+
+ constructor(props) {
+ super(props);
+ this.handleChangePage = this.handleChangePage.bind(this);
+ this.handleChangeSizePerPage = this.handleChangeSizePerPage.bind(this);
+
+ let currPage;
+ let currSizePerPage;
+ const { options } = props.pagination;
+ const sizePerPageList = options.sizePerPageList || Const.SIZE_PER_PAGE_LIST;
+
+ // initialize current page
+ if (typeof options.page !== 'undefined') {
+ currPage = options.page;
+ } else if (typeof options.pageStartIndex !== 'undefined') {
+ currPage = options.pageStartIndex;
+ } else {
+ currPage = Const.PAGE_START_INDEX;
}
- constructor(props) {
- super(props);
- this.handleChangePage = this.handleChangePage.bind(this);
- this.handleChangeSizePerPage = this.handleChangeSizePerPage.bind(this);
-
- let currPage;
- let currSizePerPage;
- const options = props.pagination.options || {};
- const sizePerPageList = options.sizePerPageList || Const.SIZE_PER_PAGE_LIST;
-
- // initialize current page
- if (typeof options.page !== 'undefined') {
- currPage = options.page;
- } else if (typeof options.pageStartIndex !== 'undefined') {
- currPage = options.pageStartIndex;
- } else {
- currPage = Const.PAGE_START_INDEX;
- }
-
- // initialize current sizePerPage
- if (typeof options.sizePerPage !== 'undefined') {
- currSizePerPage = options.sizePerPage;
- } else if (typeof sizePerPageList[0] === 'object') {
- currSizePerPage = sizePerPageList[0].value;
- } else {
- currSizePerPage = sizePerPageList[0];
- }
-
- this.state = { currPage, currSizePerPage };
+ // initialize current sizePerPage
+ if (typeof options.sizePerPage !== 'undefined') {
+ currSizePerPage = options.sizePerPage;
+ } else if (typeof sizePerPageList[0] === 'object') {
+ currSizePerPage = sizePerPageList[0].value;
+ } else {
+ currSizePerPage = sizePerPageList[0];
}
- isRemote() {
- const { remote } = this.props;
- return remote === true || (typeof remote === 'object' && remote.pagination);
- }
+ this.state = { currPage, currSizePerPage };
+ }
- handleChangePage(currPage) {
- const { currSizePerPage } = this.state;
- const { pagination: { options }, onRemotePageChange } = this.props;
- if (options.onPageChange) {
- options.onPageChange(currPage, currSizePerPage);
- }
- if (this.isRemote()) {
- onRemotePageChange(currPage, currSizePerPage);
- return;
- }
- this.setState(() => {
- return {
- currPage
- };
- });
+ componentWillReceiveProps(nextProps) {
+ let needNewState = false;
+ let { currPage, currSizePerPage } = this.state;
+ const { page, sizePerPage } = nextProps.pagination.options;
+ if (typeof page !== 'undefined') {
+ currPage = page;
+ needNewState = true;
}
-
- handleChangeSizePerPage(currSizePerPage, currPage) {
- const { pagination: { options }, onRemotePageChange } = this.props;
- if (options.onSizePerPageChange) {
- options.onSizePerPageChange(currSizePerPage, currPage);
- }
- if (this.isRemote()) {
- onRemotePageChange(currPage, currSizePerPage);
- return;
- }
- this.setState(() => {
- return {
- currPage,
- currSizePerPage
- };
- });
+ if (typeof sizePerPage !== 'undefined') {
+ currSizePerPage = sizePerPage;
+ needNewState = true;
}
- render() {
- const { pagination: { Pagination, options }, store } = this.props;
- const { currPage, currSizePerPage } = this.state;
- const withFirstAndLast = typeof options.withFirstAndLast === 'undefined' ?
- Const.With_FIRST_AND_LAST : options.withFirstAndLast;
- const alwaysShowAllBtns = typeof options.alwaysShowAllBtns === 'undefined' ?
- Const.SHOW_ALL_PAGE_BTNS : options.alwaysShowAllBtns;
- const hideSizePerPage = typeof options.hideSizePerPage === 'undefined' ?
- Const.HIDE_SIZE_PER_PAGE : options.hideSizePerPage;
- const hidePageListOnlyOnePage = typeof options.hidePageListOnlyOnePage === 'undefined' ?
- Const.HIDE_PAGE_LIST_ONLY_ONE_PAGE : options.hidePageListOnlyOnePage;
- const pageStartIndex = typeof options.pageStartIndex === 'undefined' ?
- Const.PAGE_START_INDEX : options.pageStartIndex;
-
- const data = this.isRemote() ?
- this.props.data :
- getByCurrPage(store)(currPage, currSizePerPage, pageStartIndex);
-
- const base = baseElement({
- ...this.props,
- key: 'table',
- data
- });
-
- return [
- base,
-