diff --git a/packages/react-bootstrap-table2-paginator/src/context.js b/packages/react-bootstrap-table2-paginator/src/context.js index 2a60d14..7f508a3 100644 --- a/packages/react-bootstrap-table2-paginator/src/context.js +++ b/packages/react-bootstrap-table2-paginator/src/context.js @@ -1,5 +1,6 @@ /* eslint react/prop-types: 0 */ /* eslint react/require-default-props: 0 */ +/* eslint no-lonely-if: 0 */ import React from 'react'; import PropTypes from 'prop-types'; @@ -62,8 +63,14 @@ export default ( currPage = page; needNewState = true; } else { - currPage = alignPage(nextProps.data, currPage, currSizePerPage, pageStartIndex); - needNewState = true; + // user should align the page when the page is not fit to the data size when remote enable + if (!isRemotePagination()) { + const newPage = alignPage(nextProps.data, currPage, currSizePerPage, pageStartIndex); + if (currPage !== newPage) { + currPage = newPage; + needNewState = true; + } + } } if (typeof sizePerPage !== 'undefined' && currSizePerPage !== sizePerPage) { @@ -75,7 +82,6 @@ export default ( if (onPageChange) { onPageChange(currPage, currSizePerPage); } - this.currPage = currPage; this.currSizePerPage = currSizePerPage; } diff --git a/packages/react-bootstrap-table2-paginator/test/context.test.js b/packages/react-bootstrap-table2-paginator/test/context.test.js index 10820b5..4b9c30d 100644 --- a/packages/react-bootstrap-table2-paginator/test/context.test.js +++ b/packages/react-bootstrap-table2-paginator/test/context.test.js @@ -138,6 +138,7 @@ describe('PaginationContext', () => { instance = wrapper.instance(); wrapper.render(); nextProps = { + data, pagination: { options: { page: 2, @@ -167,6 +168,7 @@ describe('PaginationContext', () => { instance = wrapper.instance(); wrapper.render(); nextProps = { + data, pagination: { options: { page: 1, @@ -178,7 +180,7 @@ describe('PaginationContext', () => { }); it('shouldn\'t call options.onPageChange', () => { - expect(onPageChange).not.toHaveBeenCalled(); + expect(onPageChange).toHaveBeenCalledTimes(0); }); it('should have correct currPage', () => { @@ -195,7 +197,7 @@ describe('PaginationContext', () => { })); instance = wrapper.instance(); wrapper.render(); - nextProps = { pagination: defaultPagination }; + nextProps = { data, pagination: defaultPagination }; instance.componentWillReceiveProps(nextProps); }); @@ -216,6 +218,7 @@ describe('PaginationContext', () => { instance = wrapper.instance(); wrapper.render(); nextProps = { + data, pagination: { options: { sizePerPage: Const.SIZE_PER_PAGE_LIST[2], @@ -245,6 +248,7 @@ describe('PaginationContext', () => { instance = wrapper.instance(); wrapper.render(); nextProps = { + data, pagination: { options: { sizePerPage: Const.SIZE_PER_PAGE_LIST[0], @@ -255,8 +259,8 @@ describe('PaginationContext', () => { instance.componentWillReceiveProps(nextProps); }); - it('shouldn\'t call options.onPageChange', () => { - expect(onPageChange).not.toHaveBeenCalled(); + it('shouldn\'t call options.onPageChange', () => { + expect(onPageChange).toHaveBeenCalledTimes(0); }); it('should have correct currSizePerPage', () => { @@ -273,7 +277,7 @@ describe('PaginationContext', () => { })); instance = wrapper.instance(); wrapper.render(); - nextProps = { pagination: defaultPagination }; + nextProps = { data, pagination: defaultPagination }; instance.componentWillReceiveProps(nextProps); });