-
Notifications
You must be signed in to change notification settings - Fork 244
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
Setting new items results in a re-submit of server-side paging #155
Comments
You can use the "paginationApi" to emit the pageChange-event only when the user clicks back or forth: ...
export class PaginationControlsComponent {
@Output() pageChange: EventEmitter<any> = new EventEmitter<any>();
@Input() id: number;
@ViewChild('paginationApi') paginationApi: PaginationControlsDirective;
private _currentPage: number;
private _lastPage: number;
constructor() {
'ngInject';
}
setCurrent(page: number) {
if (this._lastPage !== page) {
this._lastPage = this._currentPage;
this._currentPage = page;
this.paginationApi.setCurrent(page);
this.pageChange.emit(page);
}
}
next() {
if (!this.paginationApi.isLastPage()) {
const currentPage = this.paginationApi.getCurrent();
this.setCurrent(currentPage + 1);
}
}
previous() {
const currentPage = this.paginationApi.getCurrent();
if (currentPage !== 1) {
this.setCurrent(currentPage - 1);
}
}
} |
Hi, Thanks for reporting the issue. I think it might be worthwhile to create a second event, perhaps I will look into making this change in the next update I make for the lib. Not sure when I'll get round to it. I hope your work-around is sufficient for the time-being. |
Hi, Did you solve this issue? Thanks |
@michaelbromley . Hi Michael. Is this fixed? I currently have the same problem until now. Thanks |
Hi all. I'll look into getting this feature implemented and releasing a new major version soon, maybe today. |
@michaelbromley. Thanks! Looking forward to it later :) |
@michaelbromley. Hi Michael. Did you already deployed it in NPM? |
Fixed in v5.0.0! Note that this is a breaking change. See Changelog for more details: https://github.com/michaelbromley/ngx-pagination/blob/master/CHANGELOG.md#500-2019-12-02 |
@jtan80813 yes, this is now published on npm. |
Angular version: 2.4.4
ngx-pagination version: 3.0.0
Description of issue:
When new items are set in a list that is being paginated, and the total items are fewer than those shown on the current page, ngx-pagination switches pages and emits a "pageChange" event. In the case of server-side paging, this results in re-submitting the server-side request.
Steps to reproduce:
For example: The user searches on server and receives the first 10 items of a 20-result set (totalItems: 20, itemsPerPage: 10). The user jumps to the second page and a request is made to fetch the second set of 10 items. Finally, the user executes a new search that only contains a total of 8 items. This results in ngx-pagination switching to page one, thereby triggering a "pageChange" event and triggering a second, unwanted backend paging request.
Expected result:
When setting new items in a list that have fewer totalItems than the previous set of items, the page should be changed but no pageChange event should be emitted. Alternatively, there should be two types of pageChange events, one for user-triggered page changes and one for page changes that are automatically executed due to changes in totalItems.
Actual result:
A second, unwanted server paging request is executed.
Demo: (if possible, edit this Plunker demo and paste the link to your fork)
Any relevant code:
The text was updated successfully, but these errors were encountered: