options.page property is not respected
I've implemented some remote loading of data for a large table I'm working with, everything seems to be working great with the data loading and events, however the paginator keeps on "jumping" back to page 1 when I click on something. I'm setting this through the options={{page: this.props.page}} property on BootstrapTable, but when I set it to page: 3 for example, page 1 stays selected.
Any ideas? If anyone wants screenshots / code that does this I can flush this out in more detail, just let me know :)
Thanks!
Any ideas? If anyone wants screenshots / code that does this I can flush this out in more detail, just let me know :)
it's welcome! more detail more better
Ran into this one myself - @riguy724 try using the prop name of currentPage, not page.
However, @AllenFang it does look like the documentation on this is currently incorrect.
See: http://allenfang.github.io/react-bootstrap-table/docs.html
@aghreed, how did you set currentpage to control? In my opinion, only the page in options is only way to configure the default page.
Actually, there's a currPage in table state, you can change it, and it only work for changing page but the date is still the data of previous page,
Yep. @AllenFang you are correct. I was mistaken. My apologies!
I just ran into this issue in my project. Haven't had time to find out exactly why yet. But I have found a workaround. If you assign a ref to the table, you can do:
this.refs.table.handlePaginationData(3, this.refs.table.props.options.sizePerPage);
@neroleung, could you please give me a minimal and simple code which can reproduce this issue? Thanks :)
@AllenFang, I was going to add an example in my fork in the gh-pages. But how did you pack thing into the bundle.js file? Webpack? Please let me know if there's any instructions around. Thanks!
@neroleung, you just give me the code(Ensure it can reproduce this issue) and I'll pack it :) You can also post here if it's very small and simple. Thanks you
@AllenFang, take a look at this https://neroleung.github.io/react-bootstrap-table/nero_examples.html. I re-used and just modified the remote-paging example a little bit. Notice the options - page is 2. The pagingation is at page 2 at the bottom. But the data being shown is page 1.
Similar situation happens if you ajax in the data, except that the pagination wouldn't point to page 2. Because by the time the Pagination is render, the ajax get would still not be done yet.
@neroleung, Actually, remote means you need to handle the data changing every time, so in your example, when you give page 2, you should give the data corresponding to page 2, for example,
page 1 > row 0 ~ row 4
page 2 > row 5 ~ row 9
Notice here, no matter page or sizePerPage change, you need to reassign the data for react-bootstrap-table.
This is an advantage with remote on pagination, because react-bootstrap-table always handle the data which in current page, we dont hold all the data and do pagination inside.
For you example, you just slice the correct rows in the constructor:
super(props);
this.products = getProducts();
const currentIndex = (this.props.currentPage - 1) * this.props.sizePerPage;
this.state = {
data: this.products.slice(currentIndex, currentIndex + this.props.sizePerPage),
totalDataSize: this.products.length,
sizePerPage: this.props.sizePerPage,
currentPage: this.props.currentPage
};