一、组件中使用
import Pagination from '@components/pagination';
this.state = {
total: 50,
current:1,
pageSize:10,
}
componentDidMount() {
this.onChangeCurPageOrPageSize(1, 10)
}
<Pagination
current = { this.state.current }
pageSize = { this.state.pageSize }
total={this.state.total}
handleChange={this.onChangeCurPageOrPageSize}
pageSizeOptions={['10','20','30']}
></Pagination>
searchBtn = (e) => {
e && e.preventDefault()
this.onChangeCurPageOrPageSize(1, this.state.pageSize)
}
handleReset = () => {
this.props.form.resetFields();
this.onChangeCurPageOrPageSize(1, 10);
}
onChangeCurPageOrPageSize = (current, pageSize) => {
this.setState(() => ({ current, pageSize }), () => { this.handleSearch() })
}
handleSearch = (e) => {
...
}
二、pagination.js
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { Pagination } from 'antd';
class reportTemplateItem extends Component {
static propTypes = {
pageSizeOptions: PropTypes.array,
total: PropTypes.number,
current: PropTypes.number,
pageSize: PropTypes.number
}
static defaultProps = {
pageSizeOptions: ['5', '10', '20'],
total: 0,
current: 1,
pageSize: 5
}
constructor(props) {
super(props);
}
render() {
const { pageSizeOptions, total, current, pageSize } = this.props;
return (
<Fragment>
{total?
<div className="pagination" style={{marginTop:20,float:"right"}}>
<Pagination
pageSizeOptions = { pageSizeOptions }
pageSize = { pageSize }
showQuickJumper
showSizeChanger
showTotal = { this.showTotal }
current = {current }
total = { total }
onChange = { this.onChange }
onShowSizeChange = { this.onShowSizeChange }
style={{float:"right"}} />
</div>:''
}
</Fragment>
)
}
showTotal(total) {
return `总计 ${total} 条`;
}
onChange = (pageNumber, pageSize) => {
this.props.handleChange(pageNumber, pageSize)
}
onShowSizeChange=(current, pageSize)=> {
this.props.handleChange(1, pageSize)
}
}
export default reportTemplateItem;