Fra*_*eli 4 reactjs react-table
我已经完成了基于实时可调整大小的容器来更改pageSize的工作:在更改页面之前,它可以很好地工作。
更改页面后,如果减小容器的高度,则表格的高度不能低于更改页面时的高度。
换句话说,当我更改页面时(例如,从第1页更改为第2页),假设高度为360px,带有约12行,如果我走得更高,则会平滑地“添加” 360px行,但是当我低于360px时,桌子的高度不再改变。
注意:更改页面之前,所有操作均正常进行。
export default class Table extends React.Component {
constructor() {
...
}
componentWillReceiveProps(newProps) {
if (this.props.y != newProps.y) {
// size row
let rowHeight = 32.88;
// size resizable panel
let panelHeight = newProps.y;
// size of the extra y of the table (header + footer)
let extraTable = 27 + (this.props.x < 650 ? 75 : 45);
// setting pageSize of the table
this.setState({pageSize: parseInt((panelHeight - extraTable) / rowHeight)});
}
}
render() {
return (
<ReactTable
data={this.props.data}
columns={this.props.columns}
pageSize={this.state.pageSize}
/>
)
}
}
Run Code Online (Sandbox Code Playgroud)
在Github上,有人告诉我这是一个实现问题,但我觉得可以解决。有人知道如何执行此操作吗?
Solved by using the defaultPageSize instead of pageSize, and changing the key of the component to force re-render (based on the pageSize itself):
render() {
return (
<ReactTable
key={this.state.pageSize}
data={this.data}
columns={this.columns}
defaultPageSize={this.state.pageSize}
showPageSizeOptions={false}
/>
)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4135 次 |
| 最近记录: |