【问题标题】:How to programatically navigate to the last or n-th page of antd table component?如何以编程方式导航到 antd table 组件的最后一页或第 n 页?
【发布时间】:2017-01-27 17:11:50
【问题描述】:

我正在使用分页组件向 antd 表格组件添加一个新项目,并希望将表格内容导航到分页中的最后一页或第 n 页。如何通过 antd 分页以编程方式导航到 antd table 组件的最后一页或第 n 页?

【问题讨论】:

    标签: reactjs pagination antd


    【解决方案1】:

    你可以通过Table[pagination]控制它,见:https://ant.design/components/table/#Table

    【讨论】:

      【解决方案2】:

      我就是这样解决的:

      1) 向组件状态添加分页对象

      constructor(props) {
              super(props);
      
              this.state =
                  {
                      pagination: null,
                  };
          }
      

      2) 将组件状态的分页传递给组件渲染方法中的 Tables 分页属性:

          ...
          <Table
              dataSource={dataSource}
              ...
              pagination={this.state.pagination}
          />
          ...
      

      3) 在您选择的组件事件处理程序中,您现在可以使用 SetState 来设置分页对象。例如,在将新项目添加到表格后,我导航到分页的最后一页:

      handleCreateItem = () => {
              ...
              let pagination = {
                  current: YourNewCurrentPageInPagination,
                  maxSize: YourNewMaxSizeGridValue
              }
              ...
              this.setState({
                  pagination: pagination
              })
              ...
      }
      

      【讨论】:

      • 嗨,我在同一个问题上。你是如何计算 YourNewCurrentPageInPagination 的??
      猜你喜欢
      • 1970-01-01
      • 2014-01-18
      • 2013-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      相关资源
      最近更新 更多