-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.js
211 lines (146 loc) · 3.07 KB
/
table.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
let no=10;
let bflag=0;
let arr=[];
let column=[];
let thtml="";
function isEmpty(obj) {
for(var key in obj) {
if(obj.hasOwnProperty(key))
return false;
}
return true;
}
function paginate(no,d,pno)
{
if(no===undefined)
no=1;
if(pno===undefined)
pno=1;
let res=2;
if(d===undefined)
{
}
if(bflag==0)
{
let hea=[];
for(var i=0,row;row=d.rows[i];i++)
{
let v2={};
for (var j = 0, col; col = row.cells[j]; j++)
{
if(i==0)
{
hea.push(col.innerHTML);
}
else
{
v2[hea[j]]=col.innerHTML;
}
}
if(!isEmpty(v2))
arr.push(v2);
}
}
let f=0;
thtml="<table>";
let val = arr[0];
thtml+="<tr>";
for(var j in val)
{
let sub_key = j;
let sub_val = val[j];
if(f==0)
{
thtml+="<th>"+sub_key+"</th>";
}
}
recordvar=pno*no-no;
recordlimit=recordvar+no;
thtml+="</tr>";
f=1;recordflag=1;
for(var i=recordvar;i<recordlimit;i++)
{
if(i<arr.length)
{
let key = i;thtml+="<tr>";
let val = arr[i];
for(var j in val)
{
let sub_key = j;
let sub_val = val[j];
thtml+="<td >"+sub_val+"</td>";
}
thtml+="</tr>";
recordflag++;
}
}
if(arr.length%no==0)
let nobtn=arr.length/no;
else
let nobtn=parseInt(arr.length/no) +1;
thtml+="</table>";
d.innerHTML=thtml;
if( arr.length!=no) || no==1)
{
if(bflag!=0)
{
document.getElementsByClassName("tblebtngroup").remove();
}
let tbhtml="";
let el=document.createElement("div");
el.className="tblebtngroup";
tbhtml+="<br/>";
for(var i=1;i<=nobtn;i++)
{
if(nobtn>4)
{
if(i==1)
{ tbhtml+="<button class='tbtn' id='"+i+"'>"+i+"</button>";
}
else if(i==nobtn)
{tbhtml+="<button class='tbtn' id='"+i+"'>"+i+"</button>";
}
else
{
if(i+1==pno||i-1==pno||i==pno||i+5==pno||i+10==pno||i-5==pno||i-10==pno)
{
tbhtml+="<button class='tbtn' id='"+i+"'>"+i+"</button>";
}
else
{
tbhtml+="<span></span>";
}
}
}
else
tbhtml+="<button class='tbtn' id='"+i+"'>"+i+"</button>";
}
el.setAttribute("style", "width:150px ; margin: 0 auto;");
el.innerHTML=tbhtml;
insertAfter(el,d);
}
bflag++;
// BUTTON CLICK HERE ///
let classname = document.getElementsByClassName("tbtn");
for (var i = 0; i < classname.length; i++)
{
classname[i].addEventListener('click', function(){
paginate(no,d,this.id)
}, false);
}
}
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--)
{
if(this[i] && this[i].parentElement)
{
this[i].parentElement.removeChild(this[i]);
}
}
}
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}