pager.component.ts
4.61 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { Component, OnInit, OnChanges, Input, Output, EventEmitter,
Renderer, ElementRef, ViewChild } from "@angular/core";
@Component({
selector: 'admin-pager',
templateUrl: './pager.component.html',
})
export class PagerComponent implements OnInit, OnChanges {
@Output() pagerEvent: EventEmitter<any> = new EventEmitter<any>();
@Input() pageNo: number;
@Input() pageLength: number;
@Input() recordCount: number;
pageList: any;
pageShowList: any;
totalPages: number;
ngOnInit(){
//this.pageLength = 10;
this.pageShowList = [];
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo + i;
}
this.pagerEvent.emit(this.pageNo + ', ' + this.pageLength);
//this.SearchLicenses();
}
ngOnChanges(){
this.pageList = [];
if ((this.recordCount % this.pageLength) == 0) {
this.totalPages = parseInt((this.recordCount / this.pageLength).toString());
}
else {
this.totalPages = parseInt((this.recordCount / this.pageLength).toString()) + 1;
}
for(var i = 0; i < this.totalPages; i++){
this.pageList.push(i + 1);
}
this.pageShowList = [];
if(this.totalPages > 12){
if((this.pageNo % 12) != 0) {
for(var i = 0; i < 12; i++){
this.pageShowList[i] = (this.pageNo - (this.pageNo % 12)) + i + 1;
}
}
else{
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo - 12 + i + 1;
}
}
}
else{
for(var i = 0; i < 12; i++){
this.pageShowList[i] = i + 1;
}
}
}
PageLengthChange(element: any){
this.pageLength = parseInt(element.value);
this.pageNo = 1;
this.pageShowList = [];
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo + i;
}
this.pagerEvent.emit(this.pageNo + ', ' + this.pageLength);
}
PageNumberChange(element: any){
if(element.innerText !=undefined && element.innerText != ''){
if(element.innerText.indexOf('<') > -1) {
if(this.pageNo == 1) return;
this.pageNo = this.pageNo - 1;
if(this.pageNo < this.pageShowList[0]){
this.pageNo = this.pageShowList[0] - 1;
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo - i;
}
}
}
else
if(element.innerText.indexOf('>') > -1) {
if(this.pageNo >= this.totalPages) return;
this.pageNo = this.pageNo + 1;
if(this.pageNo > this.pageShowList[11]){
this.pageNo = this.pageShowList[11] + 1;
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo + i;
}
}
}
else
if(element.innerText.indexOf('Prev') > -1) {
if(this.pageShowList[0] == 1) return;
this.pageNo = this.pageShowList[0] - 12;
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo + i;
}
}
else
if(element.innerText.indexOf('Next') > -1) {
if(this.pageShowList[11] >= this.totalPages) return;
this.pageNo = this.pageShowList[11] + 1;
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo + i;
}
}
else
{
if(parseInt(element.innerText) > this.totalPages) return;
this.pageNo = parseInt(element.innerText);
}
}
else{
this.pageNo = parseInt(element);
if(this.totalPages > 12){
if((this.pageNo % 12) != 0) {
for(var i = 0; i < 12; i++){
this.pageShowList[i] = (this.pageNo - (this.pageNo % 12)) + i + 1;
}
}
else{
for(var i = 0; i < 12; i++){
this.pageShowList[i] = this.pageNo - 12 + i + 1;
}
}
}
else{
for(var i = 0; i < 12; i++){
this.pageShowList[i] = i + 1;
}
}
}
this.pagerEvent.emit(this.pageNo + ', ' + this.pageLength);
}
}