mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
update pagination on count 0 (#3228)
This commit is contained in:
committed by
Eugenio Romano
parent
8f27cd1758
commit
95a2a54017
@@ -750,6 +750,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
|||||||
}
|
}
|
||||||
|
|
||||||
updatePagination(pagination: PaginationModel) {
|
updatePagination(pagination: PaginationModel) {
|
||||||
|
this.pagination.next(pagination);
|
||||||
this.reload();
|
this.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -303,5 +303,30 @@ describe('PaginationComponent', () => {
|
|||||||
expect(component.current).toBe(2);
|
expect(component.current).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should go to previous page if current page has 0 items', () => {
|
||||||
|
const customComponent = <PaginatedComponent> {
|
||||||
|
updatePagination() {},
|
||||||
|
pagination: new BehaviorSubject<Pagination>({})
|
||||||
|
};
|
||||||
|
|
||||||
|
component.target = customComponent;
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
customComponent.pagination.next({
|
||||||
|
count: 2,
|
||||||
|
skipCount: 5,
|
||||||
|
maxItems: 5
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(component.current).toBe(2);
|
||||||
|
|
||||||
|
customComponent.pagination.next({
|
||||||
|
count: 0,
|
||||||
|
totalItems: 5,
|
||||||
|
maxItems: 5
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(component.current).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -87,6 +87,11 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.target) {
|
if (this.target) {
|
||||||
this.paginationSubscription = this.target.pagination.subscribe((pagination: PaginationModel) => {
|
this.paginationSubscription = this.target.pagination.subscribe((pagination: PaginationModel) => {
|
||||||
|
|
||||||
|
if (pagination.count === 0 && !this.isFirstPage) {
|
||||||
|
this.goPrevious();
|
||||||
|
}
|
||||||
|
|
||||||
this.pagination = pagination;
|
this.pagination = pagination;
|
||||||
this.cdr.detectChanges();
|
this.cdr.detectChanges();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user