How to reset pagination to the first page when the table data changes?
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
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;
}
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. ((
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