Skip to content

Commit 424dbea

Browse files
committed
implement pageListRenderer
1 parent b261c33 commit 424dbea

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

packages/react-bootstrap-table2-paginator/src/pagination.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Pagination extends pageResolver(Component) {
108108
const {
109109
showTotal,
110110
dataSize,
111+
pageListRenderer,
111112
pageButtonRenderer,
112113
paginationTotalRenderer,
113114
sizePerPageList,
@@ -148,13 +149,20 @@ class Pagination extends pageResolver(Component) {
148149
) : null
149150
}
150151
</div>
151-
<div className={ pageListClass }>
152-
<PaginationList
153-
pages={ pages }
154-
pageButtonRenderer={ pageButtonRenderer }
155-
onPageChange={ this.handleChangePage }
156-
/>
157-
</div>
152+
{
153+
pageListRenderer ? pageListRenderer({
154+
pages,
155+
onPageChange: this.handleChangePage
156+
}) : (
157+
<div className={ pageListClass }>
158+
<PaginationList
159+
pages={ pages }
160+
pageButtonRenderer={ pageButtonRenderer }
161+
onPageChange={ this.handleChangePage }
162+
/>
163+
</div>
164+
)
165+
}
158166
</div>
159167
);
160168
}
@@ -170,6 +178,7 @@ Pagination.propTypes = {
170178
pageStartIndex: PropTypes.number,
171179
paginationSize: PropTypes.number,
172180
showTotal: PropTypes.bool,
181+
pageListRenderer: PropTypes.func,
173182
pageButtonRenderer: PropTypes.func,
174183
paginationTotalRenderer: PropTypes.func,
175184
firstPageText: PropTypes.string,
@@ -192,6 +201,7 @@ Pagination.defaultProps = {
192201
withFirstAndLast: Const.With_FIRST_AND_LAST,
193202
alwaysShowAllBtns: Const.SHOW_ALL_PAGE_BTNS,
194203
showTotal: Const.SHOW_TOTAL,
204+
pageListRenderer: null,
195205
pageButtonRenderer: null,
196206
paginationTotalRenderer: Const.PAGINATION_TOTAL,
197207
firstPageText: Const.FIRST_PAGE_TEXT,

packages/react-bootstrap-table2-paginator/src/state-context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class StateProvider extends React.Component {
7676
sizePerPageList: options.sizePerPageList || Const.SIZE_PER_PAGE_LIST,
7777
paginationSize: options.paginationSize || Const.PAGINATION_SIZE,
7878
showTotal: options.showTotal,
79+
pageListRenderer: options.pageListRenderer,
7980
pageButtonRenderer: options.pageButtonRenderer,
8081
paginationTotalRenderer: options.paginationTotalRenderer,
8182
firstPageText: options.firstPageText || Const.FIRST_PAGE_TEXT,

packages/react-bootstrap-table2-paginator/test/pagination.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ describe('Pagination', () => {
109109
});
110110
});
111111

112+
describe('when props.pageListRenderer is defined', () => {
113+
const pageListRenderer = jest.fn().mockReturnValue(null);
114+
beforeEach(() => {
115+
pageListRenderer.mockClear();
116+
const props = createMockProps({ pageListRenderer });
117+
wrapper = shallow(<Pagination { ...props } />);
118+
instance = wrapper.instance();
119+
});
120+
121+
it('should not render PaginationList', () => {
122+
expect(wrapper.find(PaginationList)).toHaveLength(0);
123+
});
124+
125+
it('should call props.pageListRenderer correctly', () => {
126+
expect(pageListRenderer).toHaveBeenCalledTimes(1);
127+
});
128+
});
129+
112130
describe('componentWillReceiveProps', () => {
113131
describe('when next props.currSizePerPage is diff than current one', () => {
114132
const nextProps = createMockProps({ currSizePerPage: 20 });

0 commit comments

Comments
 (0)