Antd Table分页查询
2019-04-25 本文已影响220人
章鱼要回家
实际中,处于性能考虑,列表查询都是分页查询。
https://blog.csdn.net/luzhaopan/article/details/84996507
https://blog.csdn.net/weixin_41652466/article/details/80745940
为<Table>添加pagination属性,pagination作为一个组件还有属性;<Pagination>有一个回调函数onchange(),用于监听页码的变化:
render() {
const { currentPage } = this.state;
const paginationProps = {
page: currentPage,
onChange : (page) => this.handleTableChange(page),
total: presentalert.pagination.Total,
}
return (
<Table
dataSource={XXX}
columns={XXX}
pagination={paginationProps}
/>
);
}
}
onchange()的第一个参数是改变后的页码,这个参数需要通过state监听。否则如果页面中存在有刷新功能的按钮,页码不会跟随页面内容回到“1”。在state中将当前页设为空:
state = {
currentPage: '',
};
onchange()调用函数handleTableChange(),注意:此时的currentPage要和onchange()的第一个参数保持一致:
handleTableChange = (pagination) => {
const { dispatch } = this.props;
this.setState({
currentPage: pagination,
})
const params = {
Current: pagination,
Size: 10,
};
dispatch({
type: 'XXX/XXX',
payload: params,
});
}
页面中有刷新功能按钮的函数中,需要将currentPage设为1:
this.setState({
currentPage: 1,
});