React Table default pagination page

别等时光非礼了梦想. 提交于 2020-02-03 10:49:06

问题


I'm new to react-table. Is it possible to set default page in the pagination mode. Is there a certain prop to handle this? F.ex. after my component mounts I'd like to have my table opened on 5th page. Thank you!


回答1:


You probably already discovered this, but to expand on hariharan's answer, you can use the state of a component to control a lot of the props of the table. For the page, you can tell the component that the page is found in the state,

<ReactTable
    ...otherProps
    page={this.state.page}
  />

And when you initialize your state, however you initialize it, have page equal to 5. For example,

class MyClassThatHasReactTableInIt extends Component {
  constructor (props) {
    super(props);
    this.state = {
      page: 5
  }
... // etc code etc

If you do this, you also need to handle the page changing yourself though. luckily, react-table makes this very easy, you can write your custom pageChange handler:

    <ReactTable
    ...otherProps
    page={this.state.page}
    onPageChange={page => this.setState({page})}
  />



回答2:


just add page prop in <ReactTable /> component

  <ReactTable
    ...otherProps
    page={5}
  />

Just change 5 to the page number that you want.



来源:https://stackoverflow.com/questions/50811171/react-table-default-pagination-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!