Skip to content

Commit

Permalink
feat: showTotal should be a function
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Jan 25, 2016
1 parent 599bf2c commit 1b652c9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -75,7 +75,7 @@ React.render(<Pagination />, container);
| pageSizeOptions | specify the sizeChanger selections | Array<String> | ['10', '20', '30', '40'] |
| onShowSizeChange | pageSize chagne callback | Function | noop |
| showQuickJump | show quick goto jumper | Bool | false |
| showTotal | show total records text | Bool | false |
| showTotal | show total records text | Function | undefined |
| className | when set "mini", show mini version | String | rc-pagination |
| simple | when set, show simple pager | Object | null |

Expand Down
19 changes: 11 additions & 8 deletions examples/jumper.js
@@ -1,20 +1,23 @@
require('rc-pagination/assets/index.less');
require('rc-select/assets/index.css');
const Pagination = require('rc-pagination');
const React = require('react');
const ReactDOM = require('react-dom');
const Select = require('rc-select');

import React from 'react';
import ReactDOM from 'react-dom';
import Select from 'rc-select';
import Pagination from 'rc-pagination';
import 'rc-pagination/assets/index.less';
import 'rc-select/assets/index.css';

function onShowSizeChange(current, pageSize) {
console.log(current);
console.log(pageSize);
}

function showTotal(total) {
return `一共 ${total} 条数据`;
}

ReactDOM.render(
<Pagination
selectComponentClass={Select}
showTotal
showTotal={showTotal}
showQuickJumper showSizeChanger pageSize={20} defaultCurrent={5} onShowSizeChange={onShowSizeChange} total={450} />,
document.getElementById('__react-content')
);
5 changes: 2 additions & 3 deletions src/Pagination.jsx
Expand Up @@ -260,7 +260,7 @@ class Pagination extends React.Component {
let totalText = null;

if (props.showTotal) {
totalText = <span className={`${prefixCls}-total-text`}>{`${locale.total}${props.total} ${locale.records}`}</span>;
totalText = <span className={`${prefixCls}-total-text`}>{props.showTotal(props.total)}</span>;
}

return (
Expand Down Expand Up @@ -301,7 +301,7 @@ Pagination.propTypes = {
selectComponentClass: React.PropTypes.func,
showQuickJumper: React.PropTypes.bool,
pageSizeOptions: React.PropTypes.arrayOf(React.PropTypes.string),
showTotal: React.PropTypes.bool,
showTotal: React.PropTypes.func,
locale: React.PropTypes.object,
};

Expand All @@ -317,7 +317,6 @@ Pagination.defaultProps = {
showQuickJumper: false,
showSizeChanger: false,
onShowSizeChange: noop,
showTotal: false,
locale: LOCALE,
};

Expand Down
3 changes: 0 additions & 3 deletions src/locale/en_US.js
Expand Up @@ -13,7 +13,4 @@ export default {
next_page: 'Next Page',
prev_5: 'Previsous 5 Pages',
next_5: 'Next 5 Pages',

total: '',
records: 'Records',
};
2 changes: 0 additions & 2 deletions src/locale/zh_CN.js
Expand Up @@ -13,6 +13,4 @@ export default {
next_page: '下一页',
prev_5: '向前 5 页',
next_5: '向后 5 页',
total: '共 ',
records: '条记录',
};

0 comments on commit 1b652c9

Please sign in to comment.