场景如下:
指定了 pagination 的 current 和 total 属性。
table 组件中有 2 页数据共 11 条、默认分页每页 10 条。
当第二页的数据只有一条时,删除了此数据,pagination 的当前页码自动变成了 1 而不是当前的 2 ,current 属性并没有起作用,另外pagination 的 onChange 事件也却并未触发。
class PaginationBug extends React.Component{
constructor(props){
super(props);
this.state = {
data: [],
columns : [{
title: 'id',
dataIndex: 'id',
}, {
title: 'name',
dataIndex: 'name',
}, {
title: 'age',
dataIndex: 'age',
},{
title: '操作',
key: 'operation',
render: (text, record, index) =>
onConfirm={() => {
console.log(record.id);
let data = this.state.data;
data.pop();
this.setState({
data: data
}, () => {
console.log(this.state.data.length);
console.log('after delete current page: ',this.state.current);
})
}}
>
删除
}],
current: 1,
}
}
componentWillMount(){ //初始化数据
let data = [];
for (let i = 0; i < 41; i++) {
data.push({
key: i,
id: i,
name: i,
age: i,
});
}
this.setState({
data: data
})
}
render(){
return (
pagination={{
total: this.state.data.length,
current: this.state.current,
onChange: (page, pageSize) => {
console.log('current page: ', page)
this.setState({
current: page
})
}
}}
bordered={true}
columns={this.state.columns}
dataSource={this.state.data}
rowKey={record => record.id}
/>
);
}
}
删除某页最后一条数据后,指定当前页码的 current 值并未改变, 但是显示的页码已经减了一。