Skip to content

Commit 794f2b8

Browse files
committed
Merge branch 'fix-pagination' of https://github.com/VictorChen/react-bootstrap-table into VictorChen-fix-pagination
2 parents ea89bf8 + acd7ba3 commit 794f2b8

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

examples/js/pagination/demo.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint max-len: 0 */
22
import React from 'react';
33
import DefaultPaginationTable from './default-pagination-table';
4+
import IconPaginationTable from './icon-pagination-table';
45
import CustomPaginationTable from './custom-pagination-table';
56
import PaginationHookTable from './pagination-hook-table';
67

@@ -17,6 +18,15 @@ class Demo extends React.Component {
1718
</div>
1819
</div>
1920
</div>
21+
<div className='col-md-offset-1 col-md-8'>
22+
<div className='panel panel-default'>
23+
<div className='panel-heading'>Icon Pagination Example</div>
24+
<div className='panel-body'>
25+
<h5>Source in /examples/js/pagination/icon-pagination-table.js</h5>
26+
<IconPaginationTable />
27+
</div>
28+
</div>
29+
</div>
2030
<div className='col-md-offset-1 col-md-8'>
2131
<div className='panel panel-default'>
2232
<div className='panel-heading'>Custom Pagination Example</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint max-len: 0 */
2+
import React from 'react';
3+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
4+
5+
6+
const products = [];
7+
8+
function addProducts(quantity) {
9+
const startId = products.length;
10+
for (let i = 0; i < quantity; i++) {
11+
const id = startId + i;
12+
products.push({
13+
id: id,
14+
name: 'Item name ' + id,
15+
price: 2100 + i
16+
});
17+
}
18+
}
19+
20+
addProducts(70);
21+
22+
export default class IconPaginationTable extends React.Component {
23+
constructor(props) {
24+
super(props);
25+
}
26+
27+
render() {
28+
const tableOptions = {
29+
prePage: <i className='glyphicon glyphicon-chevron-left' />,
30+
nextPage: <i className='glyphicon glyphicon-chevron-right' />,
31+
firstPage: <i className='glyphicon glyphicon-step-backward' />,
32+
lastPage: <i className='glyphicon glyphicon-step-forward' />
33+
};
34+
35+
return (
36+
<div>
37+
<BootstrapTable
38+
data={ products }
39+
options={ tableOptions }
40+
pagination>
41+
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
42+
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
43+
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
44+
</BootstrapTable>
45+
</div>
46+
);
47+
}
48+
}

src/pagination/PageButton.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PageButton extends Component {
1010

1111
pageBtnClick = e => {
1212
e.preventDefault();
13-
this.props.changePage(e.currentTarget.textContent);
13+
this.props.changePage(this.props.pageNumber);
1414
}
1515

1616
render() {
@@ -33,7 +33,8 @@ PageButton.propTypes = {
3333
active: PropTypes.bool,
3434
disable: PropTypes.bool,
3535
hidden: PropTypes.bool,
36-
children: PropTypes.node
36+
children: PropTypes.node,
37+
pageNumber: PropTypes.number
3738
};
3839

3940
export default PageButton;

src/pagination/PaginationList.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,29 @@ class PaginationList extends Component {
245245
true :
246246
false;
247247
let title = page + '';
248+
let pageNumber = page;
248249

249250
if (page === this.props.nextPage) {
250251
title = this.props.nextPageTitle;
252+
pageNumber = this.props.currPage + 1;
251253
} else if (page === this.props.prePage) {
252254
title = this.props.prePageTitle;
255+
pageNumber = this.props.currPage - 1;
253256
} else if (page === this.props.firstPage) {
254257
title = this.props.firstPageTitle;
258+
pageNumber = this.props.pageStartIndex;
255259
} else if (page === this.props.lastPage) {
256260
title = this.props.lastPageTitle;
261+
pageNumber = this.getLastPage();
257262
}
258263

259264
return (
260265
<PageButton key={ index }
261266
title={ title }
262267
changePage={ this.changePage }
263268
active={ isActive }
264-
disable={ isDisabled }>
269+
disable={ isDisabled }
270+
pageNumber={ pageNumber }>
265271
{ page }
266272
</PageButton>
267273
);

0 commit comments

Comments
 (0)