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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +292 -0
  3. package/dist/index.d.ts +2382 -0
  4. package/dist/index.js +11286 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/jspreadsheet.css +723 -0
  7. package/dist/jspreadsheet.themes.css +104 -0
  8. package/package.json +57 -0
  9. package/src/index.js +95 -0
  10. package/src/test.js +50 -0
  11. package/src/utils/cells.js +36 -0
  12. package/src/utils/columns.js +742 -0
  13. package/src/utils/comments.js +87 -0
  14. package/src/utils/config.js +46 -0
  15. package/src/utils/copyPaste.js +438 -0
  16. package/src/utils/data.js +419 -0
  17. package/src/utils/dispatch.js +115 -0
  18. package/src/utils/download.js +38 -0
  19. package/src/utils/editor.js +430 -0
  20. package/src/utils/events.js +1639 -0
  21. package/src/utils/factory.js +216 -0
  22. package/src/utils/filter.js +128 -0
  23. package/src/utils/footer.js +51 -0
  24. package/src/utils/freeze.js +19 -0
  25. package/src/utils/headers.js +74 -0
  26. package/src/utils/helpers.js +409 -0
  27. package/src/utils/history.js +336 -0
  28. package/src/utils/internal.js +1299 -0
  29. package/src/utils/internalHelpers.js +96 -0
  30. package/src/utils/keys.js +406 -0
  31. package/src/utils/lazyLoading.js +143 -0
  32. package/src/utils/libraryBase.js +5 -0
  33. package/src/utils/merges.js +275 -0
  34. package/src/utils/meta.js +81 -0
  35. package/src/utils/orderBy.js +185 -0
  36. package/src/utils/pagination.js +181 -0
  37. package/src/utils/rows.js +624 -0
  38. package/src/utils/search.js +83 -0
  39. package/src/utils/selection.js +744 -0
  40. package/src/utils/style.js +147 -0
  41. package/src/utils/toolbar.js +566 -0
  42. package/src/utils/version.js +9 -0
  43. package/src/utils/worksheets.js +731 -0
  44. package/src/webcomponent.js +59 -0
@@ -0,0 +1,624 @@
1
+ import jSuites from 'jsuites';
2
+ import { getNumberOfColumns } from './columns.js';
3
+ import { createCell, updateTableReferences } from './internal.js';
4
+ import dispatch from './dispatch.js';
5
+ import { isRowMerged } from './merges.js';
6
+ import { conditionalSelectionUpdate, getSelectedRows, updateCornerPosition } from './selection.js';
7
+ import { setHistory } from './history.js';
8
+ import { getColumnNameFromId, getFreezeRowTop } from './internalHelpers.js';
9
+
10
+ /**
11
+ * Create row
12
+ */
13
+ export const createRow = function (j, data) {
14
+ const obj = this;
15
+
16
+ // Create container
17
+ if (!obj.records[j]) {
18
+ obj.records[j] = [];
19
+ }
20
+ // Default data
21
+ if (!data) {
22
+ data = obj.options.data[j];
23
+ }
24
+ // New line of data to be append in the table
25
+ const row = {
26
+ element: document.createElement('tr'),
27
+ y: j,
28
+ };
29
+
30
+ obj.rows[j] = row;
31
+
32
+ row.element.setAttribute('data-y', j);
33
+ // Index
34
+ let index = null;
35
+
36
+ // Set default row height
37
+ if (obj.options.defaultRowHeight) {
38
+ row.element.style.height = obj.options.defaultRowHeight + 'px';
39
+ }
40
+
41
+ // Definitions
42
+ if (obj.options.rows && obj.options.rows[j]) {
43
+ if (obj.options.rows[j].height) {
44
+ row.element.style.height = obj.options.rows[j].height;
45
+ }
46
+ if (obj.options.rows[j].title) {
47
+ index = obj.options.rows[j].title;
48
+ }
49
+ }
50
+ if (!index) {
51
+ index = parseInt(j + 1);
52
+ }
53
+ // Row number label
54
+ const td = document.createElement('td');
55
+ td.innerHTML = index;
56
+ td.setAttribute('data-y', j);
57
+ td.className = 'jss_row';
58
+
59
+ // freeze rows
60
+ if (obj.options.freezeRows > j) {
61
+ td.classList.add('jss_frozen_row');
62
+ td.style.top = getFreezeRowTop(j, obj.options.rows);
63
+ }
64
+ row.element.appendChild(td);
65
+
66
+ const numberOfColumns = getNumberOfColumns.call(obj);
67
+
68
+ // Data columns
69
+ for (let i = 0; i < numberOfColumns; i++) {
70
+ // New column of data to be append in the line
71
+ obj.records[j][i] = {
72
+ element: createCell.call(this, i, j, data[i]),
73
+ x: i,
74
+ y: j,
75
+ };
76
+ // Add column to the row
77
+ row.element.appendChild(obj.records[j][i].element);
78
+
79
+ if (obj.options.columns && obj.options.columns[i] && typeof obj.options.columns[i].render === 'function') {
80
+ obj.options.columns[i].render(obj.records[j][i].element, data[i], parseInt(i), parseInt(j), obj, obj.options.columns[i]);
81
+ }
82
+ }
83
+
84
+ // Add row to the table body
85
+ return row;
86
+ };
87
+
88
+ /**
89
+ * Insert a new row
90
+ *
91
+ * @param mixed - number of blank lines to be insert or a single array with the data of the new row
92
+ * @param rowNumber
93
+ * @param insertBefore
94
+ * @return void
95
+ */
96
+ export const insertRow = function (mixed, rowNumber, insertBefore) {
97
+ const obj = this;
98
+
99
+ // Configuration
100
+ if (obj.options.allowInsertRow != false) {
101
+ // Records
102
+ var records = [];
103
+
104
+ // Data to be insert
105
+ let data = [];
106
+
107
+ // The insert could be lead by number of rows or the array of data
108
+ let numOfRows;
109
+
110
+ if (!Array.isArray(mixed)) {
111
+ numOfRows = typeof mixed !== 'undefined' ? mixed : 1;
112
+ } else {
113
+ numOfRows = 1;
114
+
115
+ if (mixed) {
116
+ data = mixed;
117
+ }
118
+ }
119
+
120
+ // Direction
121
+ insertBefore = insertBefore ? true : false;
122
+
123
+ // Current column number
124
+ const lastRow = obj.options.data.length - 1;
125
+
126
+ if (rowNumber == undefined || rowNumber >= parseInt(lastRow) || rowNumber < 0) {
127
+ rowNumber = lastRow;
128
+ }
129
+
130
+ const onbeforeinsertrowRecords = [];
131
+
132
+ for (let row = 0; row < numOfRows; row++) {
133
+ const newRow = [];
134
+
135
+ for (let col = 0; col < obj.options.columns.length; col++) {
136
+ newRow[col] = data[col] ? data[col] : '';
137
+ }
138
+
139
+ onbeforeinsertrowRecords.push({
140
+ row: row + rowNumber + (insertBefore ? 0 : 1),
141
+ data: newRow,
142
+ });
143
+ }
144
+
145
+ // Onbeforeinsertrow
146
+ if (dispatch.call(obj, 'onbeforeinsertrow', obj, onbeforeinsertrowRecords) === false) {
147
+ return false;
148
+ }
149
+
150
+ // Merged cells
151
+ if (obj.options.mergeCells && Object.keys(obj.options.mergeCells).length > 0) {
152
+ if (isRowMerged.call(obj, rowNumber, insertBefore).length) {
153
+ if (!confirm(jSuites.translate('This action will destroy any existing merged cells. Are you sure?'))) {
154
+ return false;
155
+ } else {
156
+ obj.destroyMerge();
157
+ }
158
+ }
159
+ }
160
+
161
+ // Clear any search
162
+ if (obj.options.search == true) {
163
+ if (obj.results && obj.results.length != obj.rows.length) {
164
+ if (confirm(jSuites.translate('This action will clear your search results. Are you sure?'))) {
165
+ obj.resetSearch();
166
+ } else {
167
+ return false;
168
+ }
169
+ }
170
+
171
+ obj.results = null;
172
+ }
173
+
174
+ // Insertbefore
175
+ const rowIndex = !insertBefore ? rowNumber + 1 : rowNumber;
176
+
177
+ // Keep the current data
178
+ const currentRecords = obj.records.splice(rowIndex);
179
+ const currentData = obj.options.data.splice(rowIndex);
180
+ const currentRows = obj.rows.splice(rowIndex);
181
+
182
+ // Adding lines
183
+ const rowRecords = [];
184
+ const rowData = [];
185
+ const rowNode = [];
186
+
187
+ for (let row = rowIndex; row < numOfRows + rowIndex; row++) {
188
+ // Push data to the data container
189
+ obj.options.data[row] = [];
190
+ for (let col = 0; col < obj.options.columns.length; col++) {
191
+ obj.options.data[row][col] = data[col] ? data[col] : '';
192
+ }
193
+ // Create row
194
+ const newRow = createRow.call(obj, row, obj.options.data[row]);
195
+ // Append node
196
+ if (currentRows[0]) {
197
+ if (Array.prototype.indexOf.call(obj.tbody.children, currentRows[0].element) >= 0) {
198
+ obj.tbody.insertBefore(newRow.element, currentRows[0].element);
199
+ }
200
+ } else {
201
+ if (Array.prototype.indexOf.call(obj.tbody.children, obj.rows[rowNumber].element) >= 0) {
202
+ obj.tbody.appendChild(newRow.element);
203
+ }
204
+ }
205
+ // Record History
206
+ rowRecords.push([...obj.records[row]]);
207
+ rowData.push([...obj.options.data[row]]);
208
+ rowNode.push(newRow);
209
+ }
210
+
211
+ // Copy the data back to the main data
212
+ Array.prototype.push.apply(obj.records, currentRecords);
213
+ Array.prototype.push.apply(obj.options.data, currentData);
214
+ Array.prototype.push.apply(obj.rows, currentRows);
215
+
216
+ for (let j = rowIndex; j < obj.rows.length; j++) {
217
+ obj.rows[j].y = j;
218
+ }
219
+
220
+ for (let j = rowIndex; j < obj.records.length; j++) {
221
+ for (let i = 0; i < obj.records[j].length; i++) {
222
+ obj.records[j][i].y = j;
223
+ }
224
+ }
225
+
226
+ // Respect pagination
227
+ if (obj.options.pagination > 0) {
228
+ obj.page(obj.pageNumber);
229
+ }
230
+
231
+ // Keep history
232
+ setHistory.call(obj, {
233
+ action: 'insertRow',
234
+ rowNumber: rowNumber,
235
+ numOfRows: numOfRows,
236
+ insertBefore: insertBefore,
237
+ rowRecords: rowRecords,
238
+ rowData: rowData,
239
+ rowNode: rowNode,
240
+ });
241
+
242
+ // Remove table references
243
+ updateTableReferences.call(obj);
244
+
245
+ // Events
246
+ dispatch.call(obj, 'oninsertrow', obj, onbeforeinsertrowRecords);
247
+ }
248
+ };
249
+
250
+ /**
251
+ * Move row
252
+ *
253
+ * @return void
254
+ */
255
+ export const moveRow = function (o, d, ignoreDom) {
256
+ const obj = this;
257
+
258
+ if (obj.options.mergeCells && Object.keys(obj.options.mergeCells).length > 0) {
259
+ let insertBefore;
260
+
261
+ if (o > d) {
262
+ insertBefore = 1;
263
+ } else {
264
+ insertBefore = 0;
265
+ }
266
+
267
+ if (isRowMerged.call(obj, o).length || isRowMerged.call(obj, d, insertBefore).length) {
268
+ if (!confirm(jSuites.translate('This action will destroy any existing merged cells. Are you sure?'))) {
269
+ return false;
270
+ } else {
271
+ obj.destroyMerge();
272
+ }
273
+ }
274
+ }
275
+
276
+ if (obj.options.search == true) {
277
+ if (obj.results && obj.results.length != obj.rows.length) {
278
+ if (confirm(jSuites.translate('This action will clear your search results. Are you sure?'))) {
279
+ obj.resetSearch();
280
+ } else {
281
+ return false;
282
+ }
283
+ }
284
+
285
+ obj.results = null;
286
+ }
287
+
288
+ if (!ignoreDom) {
289
+ if (Array.prototype.indexOf.call(obj.tbody.children, obj.rows[d].element) >= 0) {
290
+ if (o > d) {
291
+ obj.tbody.insertBefore(obj.rows[o].element, obj.rows[d].element);
292
+ } else {
293
+ obj.tbody.insertBefore(obj.rows[o].element, obj.rows[d].element.nextSibling);
294
+ }
295
+ } else {
296
+ obj.tbody.removeChild(obj.rows[o].element);
297
+ }
298
+ }
299
+
300
+ // Place references in the correct position
301
+ obj.rows.splice(d, 0, obj.rows.splice(o, 1)[0]);
302
+ obj.records.splice(d, 0, obj.records.splice(o, 1)[0]);
303
+ obj.options.data.splice(d, 0, obj.options.data.splice(o, 1)[0]);
304
+
305
+ const firstAffectedIndex = Math.min(o, d);
306
+ const lastAffectedIndex = Math.max(o, d);
307
+
308
+ for (let j = firstAffectedIndex; j <= lastAffectedIndex; j++) {
309
+ obj.rows[j].y = j;
310
+ }
311
+
312
+ for (let j = firstAffectedIndex; j <= lastAffectedIndex; j++) {
313
+ for (let i = 0; i < obj.records[j].length; i++) {
314
+ obj.records[j][i].y = j;
315
+ }
316
+ }
317
+
318
+ // Respect pagination
319
+ if (obj.options.pagination > 0 && obj.tbody.children.length != obj.options.pagination) {
320
+ obj.page(obj.pageNumber);
321
+ }
322
+
323
+ // Keeping history of changes
324
+ setHistory.call(obj, {
325
+ action: 'moveRow',
326
+ oldValue: o,
327
+ newValue: d,
328
+ });
329
+
330
+ // Update table references
331
+ updateTableReferences.call(obj);
332
+
333
+ // Events
334
+ dispatch.call(obj, 'onmoverow', obj, parseInt(o), parseInt(d), 1);
335
+ };
336
+
337
+ /**
338
+ * Delete a row by number
339
+ *
340
+ * @param integer rowNumber - row number to be excluded
341
+ * @param integer numOfRows - number of lines
342
+ * @return void
343
+ */
344
+ export const deleteRow = function (rowNumber, numOfRows) {
345
+ const obj = this;
346
+
347
+ // Global Configuration
348
+ if (obj.options.allowDeleteRow != false) {
349
+ if (obj.options.allowDeletingAllRows == true || obj.options.data.length > 1) {
350
+ // Delete row definitions
351
+ if (rowNumber == undefined) {
352
+ const number = getSelectedRows.call(obj);
353
+
354
+ if (number.length === 0) {
355
+ rowNumber = obj.options.data.length - 1;
356
+ numOfRows = 1;
357
+ } else {
358
+ rowNumber = number[0];
359
+ numOfRows = number.length;
360
+ }
361
+ }
362
+
363
+ // Last column
364
+ let lastRow = obj.options.data.length - 1;
365
+
366
+ if (rowNumber == undefined || rowNumber > lastRow || rowNumber < 0) {
367
+ rowNumber = lastRow;
368
+ }
369
+
370
+ if (!numOfRows) {
371
+ numOfRows = 1;
372
+ }
373
+
374
+ // Do not delete more than the number of records
375
+ if (rowNumber + numOfRows >= obj.options.data.length) {
376
+ numOfRows = obj.options.data.length - rowNumber;
377
+ }
378
+
379
+ // Onbeforedeleterow
380
+ const onbeforedeleterowRecords = [];
381
+ for (let i = 0; i < numOfRows; i++) {
382
+ onbeforedeleterowRecords.push(i + rowNumber);
383
+ }
384
+
385
+ if (dispatch.call(obj, 'onbeforedeleterow', obj, onbeforedeleterowRecords) === false) {
386
+ return false;
387
+ }
388
+
389
+ if (parseInt(rowNumber) > -1) {
390
+ // Merged cells
391
+ let mergeExists = false;
392
+ if (obj.options.mergeCells && Object.keys(obj.options.mergeCells).length > 0) {
393
+ for (let row = rowNumber; row < rowNumber + numOfRows; row++) {
394
+ if (isRowMerged.call(obj, row, false).length) {
395
+ mergeExists = true;
396
+ }
397
+ }
398
+ }
399
+ if (mergeExists) {
400
+ if (!confirm(jSuites.translate('This action will destroy any existing merged cells. Are you sure?'))) {
401
+ return false;
402
+ } else {
403
+ obj.destroyMerge();
404
+ }
405
+ }
406
+
407
+ // Clear any search
408
+ if (obj.options.search == true) {
409
+ if (obj.results && obj.results.length != obj.rows.length) {
410
+ if (confirm(jSuites.translate('This action will clear your search results. Are you sure?'))) {
411
+ obj.resetSearch();
412
+ } else {
413
+ return false;
414
+ }
415
+ }
416
+
417
+ obj.results = null;
418
+ }
419
+
420
+ // If delete all rows, and set allowDeletingAllRows false, will stay one row
421
+ if (obj.options.allowDeletingAllRows != true && lastRow + 1 === numOfRows) {
422
+ numOfRows--;
423
+ console.error('Jspreadsheet: It is not possible to delete the last row');
424
+ }
425
+
426
+ // Remove node
427
+ for (let row = rowNumber; row < rowNumber + numOfRows; row++) {
428
+ if (Array.prototype.indexOf.call(obj.tbody.children, obj.rows[row].element) >= 0) {
429
+ obj.rows[row].element.className = '';
430
+ obj.rows[row].element.parentNode.removeChild(obj.rows[row].element);
431
+ }
432
+ }
433
+
434
+ // Remove data
435
+ const rowRecords = obj.records.splice(rowNumber, numOfRows);
436
+ const rowData = obj.options.data.splice(rowNumber, numOfRows);
437
+ const rowNode = obj.rows.splice(rowNumber, numOfRows);
438
+
439
+ for (let j = rowNumber; j < obj.rows.length; j++) {
440
+ obj.rows[j].y = j;
441
+ }
442
+
443
+ for (let j = rowNumber; j < obj.records.length; j++) {
444
+ for (let i = 0; i < obj.records[j].length; i++) {
445
+ obj.records[j][i].y = j;
446
+ }
447
+ }
448
+
449
+ // Respect pagination
450
+ if (obj.options.pagination > 0 && obj.tbody.children.length != obj.options.pagination) {
451
+ obj.page(obj.pageNumber);
452
+ }
453
+
454
+ // Remove selection
455
+ conditionalSelectionUpdate.call(obj, 1, rowNumber, rowNumber + numOfRows - 1);
456
+
457
+ // Keep history
458
+ setHistory.call(obj, {
459
+ action: 'deleteRow',
460
+ rowNumber: rowNumber,
461
+ numOfRows: numOfRows,
462
+ insertBefore: 1,
463
+ rowRecords: rowRecords,
464
+ rowData: rowData,
465
+ rowNode: rowNode,
466
+ });
467
+
468
+ // Remove table references
469
+ updateTableReferences.call(obj);
470
+
471
+ // Events
472
+ dispatch.call(obj, 'ondeleterow', obj, onbeforedeleterowRecords);
473
+ }
474
+ } else {
475
+ console.error('Jspreadsheet: It is not possible to delete the last row');
476
+ }
477
+ }
478
+ };
479
+
480
+ /**
481
+ * Get the row height
482
+ *
483
+ * @param row - row number (first row is: 0)
484
+ * @return height - current row height
485
+ */
486
+ export const getHeight = function (row) {
487
+ const obj = this;
488
+
489
+ let data;
490
+
491
+ if (typeof row === 'undefined') {
492
+ // Get height of all rows
493
+ data = [];
494
+ for (let j = 0; j < obj.rows.length; j++) {
495
+ const h = obj.rows[j].element.style.height;
496
+ if (h) {
497
+ data[j] = h;
498
+ }
499
+ }
500
+ } else {
501
+ // In case the row is an object
502
+ if (typeof row == 'object') {
503
+ row = row.getAttribute('data-y');
504
+ }
505
+
506
+ data = obj.rows[row].element.style.height;
507
+ }
508
+
509
+ return data;
510
+ };
511
+
512
+ /**
513
+ * Set the row height
514
+ *
515
+ * @param row - row number (first row is: 0)
516
+ * @param height - new row height
517
+ * @param oldHeight - old row height
518
+ */
519
+ export const setHeight = function (row, height, oldHeight) {
520
+ const obj = this;
521
+
522
+ if (height > 0) {
523
+ // Oldwidth
524
+ if (!oldHeight) {
525
+ oldHeight = obj.rows[row].element.getAttribute('height');
526
+
527
+ if (!oldHeight) {
528
+ const rect = obj.rows[row].element.getBoundingClientRect();
529
+ oldHeight = rect.height;
530
+ }
531
+ }
532
+
533
+ // Integer
534
+ height = parseInt(height);
535
+
536
+ // Set width
537
+ obj.rows[row].element.style.height = height + 'px';
538
+
539
+ if (!obj.options.rows) {
540
+ obj.options.rows = [];
541
+ }
542
+
543
+ // Keep options updated
544
+ if (!obj.options.rows[row]) {
545
+ obj.options.rows[row] = {};
546
+ }
547
+ obj.options.rows[row].height = height;
548
+
549
+ // Keeping history of changes
550
+ setHistory.call(obj, {
551
+ action: 'setHeight',
552
+ row: row,
553
+ oldValue: oldHeight,
554
+ newValue: height,
555
+ });
556
+
557
+ // On resize column
558
+ dispatch.call(obj, 'onresizerow', obj, row, height, oldHeight);
559
+
560
+ // Update corner position
561
+ updateCornerPosition.call(obj);
562
+ }
563
+ };
564
+
565
+ /**
566
+ * Show row
567
+ */
568
+ export const showRow = function (rowNumber) {
569
+ const obj = this;
570
+
571
+ if (!Array.isArray(rowNumber)) {
572
+ rowNumber = [rowNumber];
573
+ }
574
+
575
+ rowNumber.forEach(function (rowIndex) {
576
+ obj.rows[rowIndex].element.style.display = '';
577
+ });
578
+ };
579
+
580
+ /**
581
+ * Hide row
582
+ */
583
+ export const hideRow = function (rowNumber) {
584
+ const obj = this;
585
+
586
+ if (!Array.isArray(rowNumber)) {
587
+ rowNumber = [rowNumber];
588
+ }
589
+
590
+ rowNumber.forEach(function (rowIndex) {
591
+ obj.rows[rowIndex].element.style.display = 'none';
592
+ });
593
+ };
594
+
595
+ /**
596
+ * Get a row data by rowNumber
597
+ */
598
+ export const getRowData = function (rowNumber, processed) {
599
+ const obj = this;
600
+
601
+ if (processed) {
602
+ return obj.records[rowNumber].map(function (record) {
603
+ return record.element.innerHTML;
604
+ });
605
+ } else {
606
+ return obj.options.data[rowNumber];
607
+ }
608
+ };
609
+
610
+ /**
611
+ * Set a row data by rowNumber
612
+ */
613
+ export const setRowData = function (rowNumber, data, force) {
614
+ const obj = this;
615
+
616
+ for (let i = 0; i < obj.headers.length; i++) {
617
+ // Update cell
618
+ const columnName = getColumnNameFromId([i, rowNumber]);
619
+ // Set value
620
+ if (data[i] != null) {
621
+ obj.setValue(columnName, data[i], force);
622
+ }
623
+ }
624
+ };
@@ -0,0 +1,83 @@
1
+ import { resetFilters } from './filter.js';
2
+ import { getIdFromColumnName } from './internalHelpers.js';
3
+ import { updateResult } from './internal.js';
4
+ import { isRowMerged } from './merges.js';
5
+
6
+ /**
7
+ * Search
8
+ */
9
+ export const search = function (query) {
10
+ const obj = this;
11
+
12
+ // Reset any filter
13
+ if (obj.options.filters) {
14
+ resetFilters.call(obj);
15
+ }
16
+
17
+ // Reset selection
18
+ obj.resetSelection();
19
+
20
+ // Total of results
21
+ obj.pageNumber = 0;
22
+ obj.results = [];
23
+
24
+ if (query) {
25
+ if (obj.searchInput.value !== query) {
26
+ obj.searchInput.value = query;
27
+ }
28
+
29
+ // Search filter
30
+ const search = function (item, query, index) {
31
+ for (let i = 0; i < item.length; i++) {
32
+ if (('' + item[i]).toLowerCase().search(query) >= 0 || ('' + obj.records[index][i].element.innerHTML).toLowerCase().search(query) >= 0) {
33
+ return true;
34
+ }
35
+ }
36
+ return false;
37
+ };
38
+
39
+ // Result
40
+ const addToResult = function (k) {
41
+ if (obj.results.indexOf(k) == -1) {
42
+ obj.results.push(k);
43
+ }
44
+ };
45
+
46
+ let parsedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
47
+ parsedQuery = new RegExp(parsedQuery, 'i');
48
+
49
+ // Filter
50
+ obj.options.data.forEach(function (v, k) {
51
+ if (search(v, parsedQuery, k)) {
52
+ // Merged rows found
53
+ const rows = isRowMerged.call(obj, k);
54
+ if (rows.length) {
55
+ for (let i = 0; i < rows.length; i++) {
56
+ const row = getIdFromColumnName(rows[i], true);
57
+ for (let j = 0; j < obj.options.mergeCells[rows[i]][1]; j++) {
58
+ addToResult(row[1] + j);
59
+ }
60
+ }
61
+ } else {
62
+ // Normal row found
63
+ addToResult(k);
64
+ }
65
+ }
66
+ });
67
+ } else {
68
+ obj.results = null;
69
+ }
70
+
71
+ updateResult.call(obj);
72
+ };
73
+
74
+ /**
75
+ * Reset search
76
+ */
77
+ export const resetSearch = function () {
78
+ const obj = this;
79
+
80
+ obj.searchInput.value = '';
81
+ obj.search('');
82
+ obj.results = null;
83
+ };