Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change page programmatically #86

Closed
phaeton2040 opened this issue Jun 16, 2016 · 8 comments
Closed

Change page programmatically #86

phaeton2040 opened this issue Jun 16, 2016 · 8 comments

Comments

@phaeton2040
Copy link

I need to change page programmatically without clicking on certain page label:
image
Here user will input a page number, press enter and go to it. But if I enter a page number it is not stored in component's variable 'selected', so if I click on next arrow component goes to 2nd page not 6th (see image). That happens because 'clickCallback' is invoked directly in my component. Is there a way to update currently selected page from outside code?

@AdeleD
Copy link
Owner

AdeleD commented Jun 16, 2016

Hi @phaeton2040,
You can pass the currently selected page to react-paginate thanks to the prop called forceSelected.

<ReactPaginate clickCallback={this.handlePageClick}
               pageNum={this.state.pageNum}
               forceSelected={4} />

@phaeton2040
Copy link
Author

@AdeleD , thnx for the answer. Actually it is already done. But it didn't work because I used version 1.0 where there was no 'shouldComponentUpdate' and because of this setting 'forceSelected' property had no effect on updates. I upgraded to 2.0 and now it works fine! Issue may be closed

@cAstraea
Copy link

cAstraea commented Jun 24, 2016

Hello ,
Is it possible to update the selected page from another component ?
This is the problem I'm having http://recordit.co/TU5Wy2OI5W
I need the starting page to be at 1 when the ProductSearchForm component changes as it now remembers the last page it was on.
How can I approach this?

@petertdinh
Copy link

Hi @AdeleD ,

Running into some problems trying to mess with the forceSelected prop. I don't entirely understand it. This is my approach right now.

this.state = { pageNum: 30, currentPage: 0,  forceSelected: 0 };

someMethod() {
  //force it to the first page
  this.setState({forceSelected: 0});
}

handlePageClick= (data) => {
  this.setState({currentPage: data.selected});
}

render() {
  <ReactPaginate clickCallback={this.handlePageClick}
                 pageNum={this.state.pageNum}
                 forceSelected={this.state.forceSelected} />
}

Unfortunately this isn't working for me. What can I do to force the selected page in the parent component?

@nguyenbathanh
Copy link

Any implementation for this?

@jraut
Copy link

jraut commented Feb 2, 2017

This is an issue if using react-router. If you push a navigation event to /paginated/10 and then cancel it in the route's onEnter (by replace(prevState.location.pathname);) the pagination updates altough forceSelected stays the same.

So selected in state does not follow the changes to forceSelected after handling onPageChange altough it receives new props.

@drellow
Copy link

drellow commented Mar 31, 2017

@petertdinh did you ever find a solution or workaround for forcing the page to update within the component?

@WynnL
Copy link

WynnL commented Nov 15, 2018

For some reason every number but 0 works for the forcePage property. Is it just me or is this a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants