Skip to content

Commit

Permalink
fix(pagination) Keep start page number (edcarroll#286)
Browse files Browse the repository at this point in the history
* fix(pagination) Keep start page number

* Update pageCount inside collectionSize

* Move pageSize above collectionSize setter

* remove trailing whitespace
  • Loading branch information
liammann authored and mcosta74 committed Sep 21, 2017
1 parent 1cebf2a commit 1324e37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/collections/pagination/components/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,14 @@ describe("Pagination", () => {
expect(pagination.pages.length).toBe(5);
expect(pagination.hasNavigationLinks).toBe(true);
});
it("should keep the start page number", () => {
comp.collectionSize = 100;
comp.pageSize = 10;
comp.maxSize = 5;
comp.currentPage = 5;

fixture.detectChanges();
expect(comp.currentPage).toBe(5);
expect(pagination.page).toBe(5);
});
});
7 changes: 4 additions & 3 deletions src/collections/pagination/components/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ export class SuiPagination implements OnChanges {
this._maxSize = (value != undefined) ? Math.max(value, 1) : undefined;
}

@Input()
public pageSize:number;

@Input()
public get collectionSize():number {
return this._collectionSize;
}

public set collectionSize(value:number) {
this._collectionSize = Math.max(value, 0);
this.pageCount = Math.max(1, Math.ceil(this._collectionSize / this.pageSize));
}

@Input()
public pageSize:number;

@Input()
public get hasNavigationLinks():boolean {
const maxSize = this._maxSize || this.pageCount;
Expand Down

0 comments on commit 1324e37

Please sign in to comment.