aurelia-bootstrap
aurelia-bootstrap copied to clipboard
Pagination: TotalItemsChange and PageSizeChanged setting currentPage to 1
For the most part this works fine and isn't noticeable. The problem arises when you are trying to keep the state of the page when a user is going forward and back through the browser history.
On my own page I was keeping that stored in a variable, every time the variable changed I would have an ajax call that would run and populate the items on the page. I did have to have a pageLoaded variable so that I didn't have an endless loop though. When a user comes to the page I'd set the page number for the pagination and then set the pageLoaded to true so my pageNumberChanged event would fire after the fact.
The problem came from the fact that after I set this to true, the following would run
AubsPaginationCustomElement.prototype.pageSizeChanged = function pageSizeChanged() {
this.currentPage = 1;
this.calculatePages();
};
Which would then fire my pageNumberChanged event effectively erasing the prior value. I'm not sure why this is set here, I would think I would set that on my own when either the pageSize or totalItems are changed. Same goes for external stuff like the user filtering, sorting, etc. I've commented this out in my code but I don't think that this should be in the source either. Just allow the user to set it in their own code.