px-jspreadsheet-ce 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +292 -0
- package/dist/index.d.ts +2382 -0
- package/dist/index.js +11286 -0
- package/dist/index.js.map +1 -0
- package/dist/jspreadsheet.css +723 -0
- package/dist/jspreadsheet.themes.css +104 -0
- package/package.json +57 -0
- package/src/index.js +95 -0
- package/src/test.js +50 -0
- package/src/utils/cells.js +36 -0
- package/src/utils/columns.js +742 -0
- package/src/utils/comments.js +87 -0
- package/src/utils/config.js +46 -0
- package/src/utils/copyPaste.js +438 -0
- package/src/utils/data.js +419 -0
- package/src/utils/dispatch.js +115 -0
- package/src/utils/download.js +38 -0
- package/src/utils/editor.js +430 -0
- package/src/utils/events.js +1639 -0
- package/src/utils/factory.js +216 -0
- package/src/utils/filter.js +128 -0
- package/src/utils/footer.js +51 -0
- package/src/utils/freeze.js +19 -0
- package/src/utils/headers.js +74 -0
- package/src/utils/helpers.js +409 -0
- package/src/utils/history.js +336 -0
- package/src/utils/internal.js +1299 -0
- package/src/utils/internalHelpers.js +96 -0
- package/src/utils/keys.js +406 -0
- package/src/utils/lazyLoading.js +143 -0
- package/src/utils/libraryBase.js +5 -0
- package/src/utils/merges.js +275 -0
- package/src/utils/meta.js +81 -0
- package/src/utils/orderBy.js +185 -0
- package/src/utils/pagination.js +181 -0
- package/src/utils/rows.js +624 -0
- package/src/utils/search.js +83 -0
- package/src/utils/selection.js +744 -0
- package/src/utils/style.js +147 -0
- package/src/utils/toolbar.js +566 -0
- package/src/utils/version.js +9 -0
- package/src/utils/worksheets.js +731 -0
- package/src/webcomponent.js +59 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getColumnName } from './helpers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper injectArray
|
|
5
|
+
*/
|
|
6
|
+
export const injectArray = function (o, idx, arr) {
|
|
7
|
+
if (idx <= o.length) {
|
|
8
|
+
return o.slice(0, idx).concat(arr).concat(o.slice(idx));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const array = o.slice(0, o.length);
|
|
12
|
+
|
|
13
|
+
while (idx > array.length) {
|
|
14
|
+
array.push(undefined);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return array.concat(arr);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Convert excel like column to jss id
|
|
22
|
+
*
|
|
23
|
+
* @param string id
|
|
24
|
+
* @return string id
|
|
25
|
+
*/
|
|
26
|
+
export const getIdFromColumnName = function (id, arr) {
|
|
27
|
+
// Get the letters
|
|
28
|
+
const t = /^[a-zA-Z]+/.exec(id);
|
|
29
|
+
|
|
30
|
+
if (t) {
|
|
31
|
+
// Base 26 calculation
|
|
32
|
+
let code = 0;
|
|
33
|
+
for (let i = 0; i < t[0].length; i++) {
|
|
34
|
+
code += parseInt(t[0].charCodeAt(i) - 64) * Math.pow(26, t[0].length - 1 - i);
|
|
35
|
+
}
|
|
36
|
+
code--;
|
|
37
|
+
// Make sure jss starts on zero
|
|
38
|
+
if (code < 0) {
|
|
39
|
+
code = 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Number
|
|
43
|
+
let number = parseInt(/[0-9]+$/.exec(id));
|
|
44
|
+
if (number > 0) {
|
|
45
|
+
number--;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (arr == true) {
|
|
49
|
+
id = [code, number];
|
|
50
|
+
} else {
|
|
51
|
+
id = code + '-' + number;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return id;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Convert jss id to excel like column name
|
|
60
|
+
*
|
|
61
|
+
* @param string id
|
|
62
|
+
* @return string id
|
|
63
|
+
*/
|
|
64
|
+
export const getColumnNameFromId = function (cellId) {
|
|
65
|
+
if (!Array.isArray(cellId)) {
|
|
66
|
+
cellId = cellId.split('-');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return getColumnName(parseInt(cellId[0])) + (parseInt(cellId[1]) + 1);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 获取静态的左侧距离
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
export const getFreezeColumnLeft = function (colNumber, columns) {
|
|
77
|
+
let left = 50; // 距离左侧的位置
|
|
78
|
+
while (colNumber > 0) {
|
|
79
|
+
const obj = columns[colNumber - 1]; // 左侧单元格
|
|
80
|
+
if (obj.type !== 'hidden') {
|
|
81
|
+
left += parseInt(obj.width);
|
|
82
|
+
}
|
|
83
|
+
colNumber -= 1;
|
|
84
|
+
}
|
|
85
|
+
return left + 'px';
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const getFreezeRowTop = function (rowNumber, rows) {
|
|
89
|
+
let top = 30; // 距离顶部的位置
|
|
90
|
+
while (rowNumber > 0) {
|
|
91
|
+
const obj = rows[rowNumber - 1]; // 左侧单元格
|
|
92
|
+
top += parseInt(obj.height);
|
|
93
|
+
rowNumber -= 1;
|
|
94
|
+
}
|
|
95
|
+
return top + 'px';
|
|
96
|
+
};
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { updateScroll } from './internal.js';
|
|
2
|
+
import { loadDown, loadPage, loadUp, loadValidation } from './lazyLoading.js';
|
|
3
|
+
|
|
4
|
+
const upGet = function (x, y) {
|
|
5
|
+
const obj = this;
|
|
6
|
+
|
|
7
|
+
x = parseInt(x);
|
|
8
|
+
y = parseInt(y);
|
|
9
|
+
for (let j = y - 1; j >= 0; j--) {
|
|
10
|
+
if (obj.records[j][x].element.style.display != 'none' && obj.rows[j].element.style.display != 'none') {
|
|
11
|
+
if (obj.records[j][x].element.getAttribute('data-merged')) {
|
|
12
|
+
if (obj.records[j][x].element == obj.records[y][x].element) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
y = j;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return y;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const upVisible = function (group, direction) {
|
|
25
|
+
const obj = this;
|
|
26
|
+
|
|
27
|
+
let x, y;
|
|
28
|
+
|
|
29
|
+
if (group == 0) {
|
|
30
|
+
x = parseInt(obj.selectedCell[0]);
|
|
31
|
+
y = parseInt(obj.selectedCell[1]);
|
|
32
|
+
} else {
|
|
33
|
+
x = parseInt(obj.selectedCell[2]);
|
|
34
|
+
y = parseInt(obj.selectedCell[3]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (direction == 0) {
|
|
38
|
+
for (let j = 0; j < y; j++) {
|
|
39
|
+
if (obj.records[j][x].element.style.display != 'none' && obj.rows[j].element.style.display != 'none') {
|
|
40
|
+
y = j;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
y = upGet.call(obj, x, y);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (group == 0) {
|
|
49
|
+
obj.selectedCell[0] = x;
|
|
50
|
+
obj.selectedCell[1] = y;
|
|
51
|
+
} else {
|
|
52
|
+
obj.selectedCell[2] = x;
|
|
53
|
+
obj.selectedCell[3] = y;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const up = function (shiftKey, ctrlKey) {
|
|
58
|
+
const obj = this;
|
|
59
|
+
|
|
60
|
+
if (shiftKey) {
|
|
61
|
+
if (obj.selectedCell[3] > 0) {
|
|
62
|
+
upVisible.call(obj, 1, ctrlKey ? 0 : 1);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (obj.selectedCell[1] > 0) {
|
|
66
|
+
upVisible.call(obj, 0, ctrlKey ? 0 : 1);
|
|
67
|
+
}
|
|
68
|
+
obj.selectedCell[2] = obj.selectedCell[0];
|
|
69
|
+
obj.selectedCell[3] = obj.selectedCell[1];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Update selection
|
|
73
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
74
|
+
|
|
75
|
+
// Change page
|
|
76
|
+
if (obj.options.lazyLoading == true) {
|
|
77
|
+
if (obj.selectedCell[1] == 0 || obj.selectedCell[3] == 0) {
|
|
78
|
+
loadPage.call(obj, 0);
|
|
79
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
80
|
+
} else {
|
|
81
|
+
if (loadValidation.call(obj)) {
|
|
82
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
83
|
+
} else {
|
|
84
|
+
const item = parseInt(obj.tbody.firstChild.getAttribute('data-y'));
|
|
85
|
+
if (obj.selectedCell[1] - item < 30) {
|
|
86
|
+
loadUp.call(obj);
|
|
87
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else if (obj.options.pagination > 0) {
|
|
92
|
+
const pageNumber = obj.whichPage(obj.selectedCell[3]);
|
|
93
|
+
if (pageNumber != obj.pageNumber) {
|
|
94
|
+
obj.page(pageNumber);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
updateScroll.call(obj, 1);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const rightGet = function (x, y) {
|
|
102
|
+
const obj = this;
|
|
103
|
+
|
|
104
|
+
x = parseInt(x);
|
|
105
|
+
y = parseInt(y);
|
|
106
|
+
|
|
107
|
+
for (let i = x + 1; i < obj.headers.length; i++) {
|
|
108
|
+
if (obj.records[y][i].element.style.display != 'none') {
|
|
109
|
+
if (obj.records[y][i].element.getAttribute('data-merged')) {
|
|
110
|
+
if (obj.records[y][i].element == obj.records[y][x].element) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
x = i;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return x;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const rightVisible = function (group, direction) {
|
|
123
|
+
const obj = this;
|
|
124
|
+
|
|
125
|
+
let x, y;
|
|
126
|
+
|
|
127
|
+
if (group == 0) {
|
|
128
|
+
x = parseInt(obj.selectedCell[0]);
|
|
129
|
+
y = parseInt(obj.selectedCell[1]);
|
|
130
|
+
} else {
|
|
131
|
+
x = parseInt(obj.selectedCell[2]);
|
|
132
|
+
y = parseInt(obj.selectedCell[3]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (direction == 0) {
|
|
136
|
+
for (let i = obj.headers.length - 1; i > x; i--) {
|
|
137
|
+
if (obj.records[y][i].element.style.display != 'none') {
|
|
138
|
+
x = i;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
x = rightGet.call(obj, x, y);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (group == 0) {
|
|
147
|
+
obj.selectedCell[0] = x;
|
|
148
|
+
obj.selectedCell[1] = y;
|
|
149
|
+
} else {
|
|
150
|
+
obj.selectedCell[2] = x;
|
|
151
|
+
obj.selectedCell[3] = y;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const right = function (shiftKey, ctrlKey) {
|
|
156
|
+
const obj = this;
|
|
157
|
+
|
|
158
|
+
if (shiftKey) {
|
|
159
|
+
if (obj.selectedCell[2] < obj.headers.length - 1) {
|
|
160
|
+
rightVisible.call(obj, 1, ctrlKey ? 0 : 1);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
if (obj.selectedCell[0] < obj.headers.length - 1) {
|
|
164
|
+
rightVisible.call(obj, 0, ctrlKey ? 0 : 1);
|
|
165
|
+
}
|
|
166
|
+
obj.selectedCell[2] = obj.selectedCell[0];
|
|
167
|
+
obj.selectedCell[3] = obj.selectedCell[1];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
171
|
+
updateScroll.call(obj, 2);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export const downGet = function (x, y) {
|
|
175
|
+
const obj = this;
|
|
176
|
+
|
|
177
|
+
x = parseInt(x);
|
|
178
|
+
y = parseInt(y);
|
|
179
|
+
for (let j = y + 1; j < obj.rows.length; j++) {
|
|
180
|
+
if (obj.records[j][x].element.style.display != 'none' && obj.rows[j].element.style.display != 'none') {
|
|
181
|
+
if (obj.records[j][x].element.getAttribute('data-merged')) {
|
|
182
|
+
if (obj.records[j][x].element == obj.records[y][x].element) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
y = j;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return y;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const downVisible = function (group, direction) {
|
|
195
|
+
const obj = this;
|
|
196
|
+
|
|
197
|
+
let x, y;
|
|
198
|
+
|
|
199
|
+
if (group == 0) {
|
|
200
|
+
x = parseInt(obj.selectedCell[0]);
|
|
201
|
+
y = parseInt(obj.selectedCell[1]);
|
|
202
|
+
} else {
|
|
203
|
+
x = parseInt(obj.selectedCell[2]);
|
|
204
|
+
y = parseInt(obj.selectedCell[3]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (direction == 0) {
|
|
208
|
+
for (let j = obj.rows.length - 1; j > y; j--) {
|
|
209
|
+
if (obj.records[j][x].element.style.display != 'none' && obj.rows[j].element.style.display != 'none') {
|
|
210
|
+
y = j;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
y = downGet.call(obj, x, y);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (group == 0) {
|
|
219
|
+
obj.selectedCell[0] = x;
|
|
220
|
+
obj.selectedCell[1] = y;
|
|
221
|
+
} else {
|
|
222
|
+
obj.selectedCell[2] = x;
|
|
223
|
+
obj.selectedCell[3] = y;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const down = function (shiftKey, ctrlKey) {
|
|
228
|
+
const obj = this;
|
|
229
|
+
|
|
230
|
+
if (shiftKey) {
|
|
231
|
+
if (obj.selectedCell[3] < obj.records.length - 1) {
|
|
232
|
+
downVisible.call(obj, 1, ctrlKey ? 0 : 1);
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
if (obj.selectedCell[1] < obj.records.length - 1) {
|
|
236
|
+
downVisible.call(obj, 0, ctrlKey ? 0 : 1);
|
|
237
|
+
}
|
|
238
|
+
obj.selectedCell[2] = obj.selectedCell[0];
|
|
239
|
+
obj.selectedCell[3] = obj.selectedCell[1];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
243
|
+
|
|
244
|
+
// Change page
|
|
245
|
+
if (obj.options.lazyLoading == true) {
|
|
246
|
+
if (obj.selectedCell[1] == obj.records.length - 1 || obj.selectedCell[3] == obj.records.length - 1) {
|
|
247
|
+
loadPage.call(obj, -1);
|
|
248
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
249
|
+
} else {
|
|
250
|
+
if (loadValidation.call(obj)) {
|
|
251
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
252
|
+
} else {
|
|
253
|
+
const item = parseInt(obj.tbody.lastChild.getAttribute('data-y'));
|
|
254
|
+
if (item - obj.selectedCell[3] < 30) {
|
|
255
|
+
loadDown.call(obj);
|
|
256
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else if (obj.options.pagination > 0) {
|
|
261
|
+
const pageNumber = obj.whichPage(obj.selectedCell[3]);
|
|
262
|
+
if (pageNumber != obj.pageNumber) {
|
|
263
|
+
obj.page(pageNumber);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
updateScroll.call(obj, 3);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const leftGet = function (x, y) {
|
|
271
|
+
const obj = this;
|
|
272
|
+
|
|
273
|
+
x = parseInt(x);
|
|
274
|
+
y = parseInt(y);
|
|
275
|
+
for (let i = x - 1; i >= 0; i--) {
|
|
276
|
+
if (obj.records[y][i].element.style.display != 'none') {
|
|
277
|
+
if (obj.records[y][i].element.getAttribute('data-merged')) {
|
|
278
|
+
if (obj.records[y][i].element == obj.records[y][x].element) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
x = i;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return x;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const leftVisible = function (group, direction) {
|
|
291
|
+
const obj = this;
|
|
292
|
+
|
|
293
|
+
let x, y;
|
|
294
|
+
|
|
295
|
+
if (group == 0) {
|
|
296
|
+
x = parseInt(obj.selectedCell[0]);
|
|
297
|
+
y = parseInt(obj.selectedCell[1]);
|
|
298
|
+
} else {
|
|
299
|
+
x = parseInt(obj.selectedCell[2]);
|
|
300
|
+
y = parseInt(obj.selectedCell[3]);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (direction == 0) {
|
|
304
|
+
for (let i = 0; i < x; i++) {
|
|
305
|
+
if (obj.records[y][i].element.style.display != 'none') {
|
|
306
|
+
x = i;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
x = leftGet.call(obj, x, y);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (group == 0) {
|
|
315
|
+
obj.selectedCell[0] = x;
|
|
316
|
+
obj.selectedCell[1] = y;
|
|
317
|
+
} else {
|
|
318
|
+
obj.selectedCell[2] = x;
|
|
319
|
+
obj.selectedCell[3] = y;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export const left = function (shiftKey, ctrlKey) {
|
|
324
|
+
const obj = this;
|
|
325
|
+
|
|
326
|
+
if (shiftKey) {
|
|
327
|
+
if (obj.selectedCell[2] > 0) {
|
|
328
|
+
leftVisible.call(obj, 1, ctrlKey ? 0 : 1);
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
if (obj.selectedCell[0] > 0) {
|
|
332
|
+
leftVisible.call(obj, 0, ctrlKey ? 0 : 1);
|
|
333
|
+
}
|
|
334
|
+
obj.selectedCell[2] = obj.selectedCell[0];
|
|
335
|
+
obj.selectedCell[3] = obj.selectedCell[1];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
339
|
+
updateScroll.call(obj, 0);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export const first = function (shiftKey, ctrlKey) {
|
|
343
|
+
const obj = this;
|
|
344
|
+
|
|
345
|
+
if (shiftKey) {
|
|
346
|
+
if (ctrlKey) {
|
|
347
|
+
obj.selectedCell[3] = 0;
|
|
348
|
+
} else {
|
|
349
|
+
leftVisible.call(obj, 1, 0);
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
if (ctrlKey) {
|
|
353
|
+
obj.selectedCell[1] = 0;
|
|
354
|
+
} else {
|
|
355
|
+
leftVisible.call(obj, 0, 0);
|
|
356
|
+
}
|
|
357
|
+
obj.selectedCell[2] = obj.selectedCell[0];
|
|
358
|
+
obj.selectedCell[3] = obj.selectedCell[1];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Change page
|
|
362
|
+
if (obj.options.lazyLoading == true && (obj.selectedCell[1] == 0 || obj.selectedCell[3] == 0)) {
|
|
363
|
+
loadPage.call(obj, 0);
|
|
364
|
+
} else if (obj.options.pagination > 0) {
|
|
365
|
+
const pageNumber = obj.whichPage(obj.selectedCell[3]);
|
|
366
|
+
if (pageNumber != obj.pageNumber) {
|
|
367
|
+
obj.page(pageNumber);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
372
|
+
updateScroll.call(obj, 1);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
export const last = function (shiftKey, ctrlKey) {
|
|
376
|
+
const obj = this;
|
|
377
|
+
|
|
378
|
+
if (shiftKey) {
|
|
379
|
+
if (ctrlKey) {
|
|
380
|
+
obj.selectedCell[3] = obj.records.length - 1;
|
|
381
|
+
} else {
|
|
382
|
+
rightVisible.call(obj, 1, 0);
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
if (ctrlKey) {
|
|
386
|
+
obj.selectedCell[1] = obj.records.length - 1;
|
|
387
|
+
} else {
|
|
388
|
+
rightVisible.call(obj, 0, 0);
|
|
389
|
+
}
|
|
390
|
+
obj.selectedCell[2] = obj.selectedCell[0];
|
|
391
|
+
obj.selectedCell[3] = obj.selectedCell[1];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Change page
|
|
395
|
+
if (obj.options.lazyLoading == true && (obj.selectedCell[1] == obj.records.length - 1 || obj.selectedCell[3] == obj.records.length - 1)) {
|
|
396
|
+
loadPage.call(obj, -1);
|
|
397
|
+
} else if (obj.options.pagination > 0) {
|
|
398
|
+
const pageNumber = obj.whichPage(obj.selectedCell[3]);
|
|
399
|
+
if (pageNumber != obj.pageNumber) {
|
|
400
|
+
obj.page(pageNumber);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
obj.updateSelectionFromCoords(obj.selectedCell[0], obj.selectedCell[1], obj.selectedCell[2], obj.selectedCell[3]);
|
|
405
|
+
updateScroll.call(obj, 3);
|
|
406
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go to a page in a lazyLoading
|
|
3
|
+
*/
|
|
4
|
+
export const loadPage = function (pageNumber) {
|
|
5
|
+
const obj = this;
|
|
6
|
+
|
|
7
|
+
// Search
|
|
8
|
+
let results;
|
|
9
|
+
|
|
10
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
11
|
+
results = obj.results;
|
|
12
|
+
} else {
|
|
13
|
+
results = obj.rows;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Per page
|
|
17
|
+
const quantityPerPage = 100;
|
|
18
|
+
|
|
19
|
+
// pageNumber
|
|
20
|
+
if (pageNumber == null || pageNumber == -1) {
|
|
21
|
+
// Last page
|
|
22
|
+
pageNumber = Math.ceil(results.length / quantityPerPage) - 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let startRow = pageNumber * quantityPerPage;
|
|
26
|
+
let finalRow = pageNumber * quantityPerPage + quantityPerPage;
|
|
27
|
+
if (finalRow > results.length) {
|
|
28
|
+
finalRow = results.length;
|
|
29
|
+
}
|
|
30
|
+
startRow = finalRow - 100;
|
|
31
|
+
if (startRow < 0) {
|
|
32
|
+
startRow = 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Appeding items
|
|
36
|
+
for (let j = startRow; j < finalRow; j++) {
|
|
37
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
38
|
+
obj.tbody.appendChild(obj.rows[results[j]].element);
|
|
39
|
+
} else {
|
|
40
|
+
obj.tbody.appendChild(obj.rows[j].element);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (obj.tbody.children.length > quantityPerPage) {
|
|
44
|
+
obj.tbody.removeChild(obj.tbody.firstChild);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const loadValidation = function () {
|
|
50
|
+
const obj = this;
|
|
51
|
+
|
|
52
|
+
if (obj.selectedCell) {
|
|
53
|
+
const currentPage = parseInt(obj.tbody.firstChild.getAttribute('data-y')) / 100;
|
|
54
|
+
const selectedPage = parseInt(obj.selectedCell[3] / 100);
|
|
55
|
+
const totalPages = parseInt(obj.rows.length / 100);
|
|
56
|
+
|
|
57
|
+
if (currentPage != selectedPage && selectedPage <= totalPages) {
|
|
58
|
+
if (!Array.prototype.indexOf.call(obj.tbody.children, obj.rows[obj.selectedCell[3]].element)) {
|
|
59
|
+
obj.loadPage(selectedPage);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const loadUp = function () {
|
|
69
|
+
const obj = this;
|
|
70
|
+
|
|
71
|
+
// Search
|
|
72
|
+
let results;
|
|
73
|
+
|
|
74
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
75
|
+
results = obj.results;
|
|
76
|
+
} else {
|
|
77
|
+
results = obj.rows;
|
|
78
|
+
}
|
|
79
|
+
let test = 0;
|
|
80
|
+
if (results.length > 100) {
|
|
81
|
+
// Get the first element in the page
|
|
82
|
+
let item = parseInt(obj.tbody.firstChild.getAttribute('data-y'));
|
|
83
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
84
|
+
item = results.indexOf(item);
|
|
85
|
+
}
|
|
86
|
+
if (item > 0) {
|
|
87
|
+
for (let j = 0; j < 30; j++) {
|
|
88
|
+
item = item - 1;
|
|
89
|
+
if (item > -1) {
|
|
90
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
91
|
+
obj.tbody.insertBefore(obj.rows[results[item]].element, obj.tbody.firstChild);
|
|
92
|
+
} else {
|
|
93
|
+
obj.tbody.insertBefore(obj.rows[item].element, obj.tbody.firstChild);
|
|
94
|
+
}
|
|
95
|
+
if (obj.tbody.children.length > 100) {
|
|
96
|
+
obj.tbody.removeChild(obj.tbody.lastChild);
|
|
97
|
+
test = 1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return test;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const loadDown = function () {
|
|
107
|
+
const obj = this;
|
|
108
|
+
|
|
109
|
+
// Search
|
|
110
|
+
let results;
|
|
111
|
+
|
|
112
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
113
|
+
results = obj.results;
|
|
114
|
+
} else {
|
|
115
|
+
results = obj.rows;
|
|
116
|
+
}
|
|
117
|
+
let test = 0;
|
|
118
|
+
if (results.length > 100) {
|
|
119
|
+
// Get the last element in the page
|
|
120
|
+
let item = parseInt(obj.tbody.lastChild.getAttribute('data-y'));
|
|
121
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
122
|
+
item = results.indexOf(item);
|
|
123
|
+
}
|
|
124
|
+
if (item < obj.rows.length - 1) {
|
|
125
|
+
for (let j = 0; j <= 30; j++) {
|
|
126
|
+
if (item < results.length) {
|
|
127
|
+
if ((obj.options.search == true || obj.options.filters == true) && obj.results) {
|
|
128
|
+
obj.tbody.appendChild(obj.rows[results[item]].element);
|
|
129
|
+
} else {
|
|
130
|
+
obj.tbody.appendChild(obj.rows[item].element);
|
|
131
|
+
}
|
|
132
|
+
if (obj.tbody.children.length > 100) {
|
|
133
|
+
obj.tbody.removeChild(obj.tbody.firstChild);
|
|
134
|
+
test = 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
item = item + 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return test;
|
|
143
|
+
};
|