-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsome.component.ts
More file actions
27 lines (26 loc) · 802 Bytes
/
Copy pathsome.component.ts
File metadata and controls
27 lines (26 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export class SomeComponent {
private delta: number = 2;
getPagination(currentPageNum, totalPageCount): Array<any> {
const pages = new Array<any>();
for (let i = 0; i < totalPageCount; i++) {
const pageNum = i + 1;
if (i === 0 || i === totalPageCount - 1) {
//add first & last page numbers.
pages.push(pageNum);
} else {
const left = currentPageNum - this.delta - 1;
const right = currentPageNum + this.delta + 1;
if (i > left - 2 && i < right) {
if (left === pageNum || right === pageNum) {
//add left & right ellipsis.
pages.push("...");
} else {
//add in-between page numbers.
pages.push(pageNum);
}
}
}
}
return pages;
}
}