react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

How to reset pagination to the first page when the table data changes?

Open saigiridhar21 opened this issue 5 years ago • 3 comments

Question How to reset pagination to the first page when the data changes?

Steps to reproduce:

  • Add a button called "Change table data" which changes the table data.
  • Change the pagination to some other page like 2.
  • Then, click on "Change table data" which changes the table data but, still the new table data will be rendered as per the second page only. Pagination will not reset to the first page.

Screenshots NA

saigiridhar21 avatar Apr 26 '21 18:04 saigiridhar21

Below is one workaround to handle this scernaio,

First, add a ref to the table like below.

   <BootstrapTable
       wrapperClasses="mapb9table responsive"
       bordered={false}
       keyField="id"
       data={products}
       columns={columns}
       ref={ n => this.node = n }
       pagination={paginationFactory(optionsPag)}
    />

Then, add the below line in the onClick method of "Change table data".

  handleGetCurrentPage = () => {
     // This updates the pagination to the first page as required in this use-case.
     this.node.paginationContext.currPage= 1; 
  }

saigiridhar21 avatar May 30 '21 14:05 saigiridhar21

Below is one workaround to handle this scernaio,

First, add a ref to the table like below.

   <BootstrapTable
       wrapperClasses="mapb9table responsive"
       bordered={false}
       keyField="id"
       data={products}
       columns={columns}
       ref={ n => this.node = n }
       pagination={paginationFactory(optionsPag)}
    />

Then, add the below line in the onClick method of "Change table data".

  handleGetCurrentPage = () => {
     // This updates the pagination to the first page as required in this use-case.
     this.node.paginationContext.currPage= 1; 
  }

Not working for me. ((

hevoc123 avatar May 30 '21 16:05 hevoc123

Below is one workaround to handle this scernaio, First, add a ref to the table like below.

   <BootstrapTable
       wrapperClasses="mapb9table responsive"
       bordered={false}
       keyField="id"
       data={products}
       columns={columns}
       ref={ n => this.node = n }
       pagination={paginationFactory(optionsPag)}
    />

Then, add the below line in the onClick method of "Change table data".

  handleGetCurrentPage = () => {
     // This updates the pagination to the first page as required in this use-case.
     this.node.paginationContext.currPage= 1; 
  }

Not working for me. ((

@hevoc123 Here is the sandbox URL which has the implementation. https://codesandbox.io/s/pagination-b7m0y?file=/src/index.js

saigiridhar21 avatar Jun 02 '21 06:06 saigiridhar21