Skip to content

Commit ede47ce

Browse files
committed
Updates
1 parent 22560e3 commit ede47ce

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

examples/pagerCount.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'rc-pagination/assets/index.less';
22
import Pagination from 'rc-pagination';
33
import React from 'react';
44
import ReactDOM from 'react-dom';
5-
6-
const total = 500;
5+
import Select from 'rc-select';
6+
import 'rc-select/assets/index.css';
77

88
const itemRender = (current, type, element) => {
99
const hideItems = ['jump-last', 'jump-first'];
@@ -15,8 +15,23 @@ const itemRender = (current, type, element) => {
1515
return element;
1616
};
1717

18+
function onShowSizeChange(current, pageSize) {
19+
console.log(current, pageSize);
20+
}
21+
1822
ReactDOM.render(
1923
<div>
20-
<Pagination total={total} itemRender={itemRender} pagerCount={10} showPrevNextJumpers={false} />
24+
<Pagination total={500} itemRender={itemRender} pagerCount={10} showPrevNextJumpers={false} />
25+
26+
<Pagination
27+
selectComponentClass={Select}
28+
showSizeChanger
29+
onShowSizeChange={onShowSizeChange}
30+
defaultCurrent={3}
31+
total={500}
32+
pagerCount={7}
33+
/>
34+
35+
<Pagination total={500} pagerCount={8} />
2136
</div>
2237
, document.getElementById('__react-content'));

src/Pagination.jsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class Pagination extends React.Component {
339339
const { pagerCount } = props;
340340
const boundaryRemainder = pagerCount % 2 === 0 ? 1 : 0;
341341
const goButton = (props.showQuickJumper && props.showQuickJumper.goButton);
342-
const halfPagerCount = Math.max(1, Math.floor(pagerCount / 2));
342+
const halfPagerCount = Math.max(1, Math.floor((pagerCount - 1) / 2));
343343
const pageBufferSize = props.showLessItems ? 1 : halfPagerCount;
344344
const { current, pageSize } = this.state;
345345

@@ -430,7 +430,7 @@ class Pagination extends React.Component {
430430
);
431431
}
432432

433-
if (allPages <= pagerCount + pageBufferSize * 2) {
433+
if (allPages <= pageBufferSize * 2 + boundaryRemainder + 1) {
434434
const pagerProps = {
435435
locale,
436436
rootPrefixCls: prefixCls,
@@ -546,15 +546,15 @@ class Pagination extends React.Component {
546546
/>
547547
);
548548

549-
let left = Math.max(1, current - pageBufferSize);
550-
let right = Math.min(current + pageBufferSize - boundaryRemainder, allPages);
549+
let left = Math.max(1, current - pageBufferSize - boundaryRemainder);
550+
let right = Math.min(current + pageBufferSize, allPages);
551551

552552
if (current - 1 <= pageBufferSize) {
553-
right = 1 + pageBufferSize * 2 - boundaryRemainder;
553+
right = 1 + pageBufferSize * 2 + boundaryRemainder;
554554
}
555555

556-
if (allPages - current <= pageBufferSize) {
557-
left = allPages - pageBufferSize * 2;
556+
if (allPages - current < pageBufferSize) {
557+
left = allPages - pageBufferSize * 2 - boundaryRemainder;
558558
}
559559

560560
for (let i = left; i <= right; i++) {
@@ -574,10 +574,7 @@ class Pagination extends React.Component {
574574
);
575575
}
576576

577-
if (
578-
current - boundaryRemainder > pageBufferSize &&
579-
current !== boundaryRemainder + pageBufferSize + 1
580-
) {
577+
if (current - boundaryRemainder - 2 > pageBufferSize) {
581578
pagerList[0] = React.cloneElement(pagerList[0], {
582579
className: `${prefixCls}-item-after-jump-prev`,
583580
});

0 commit comments

Comments
 (0)