-
Notifications
You must be signed in to change notification settings - Fork 108
/
VueExcelEditor.vue
3289 lines (3190 loc) · 124 KB
/
VueExcelEditor.vue
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<template>
<div ref="editor" class="vue-excel-editor" :style="{display: 'inline-block', width}">
<div class="component-content">
<!-- No record -->
<div v-if="localizedLabel.noRecordIndicator && pagingTable.length == 0" class="norecord" :style="{bottom: noFooter? '12px' : '37px'}">
{{ localizedLabel.noRecordIndicator }}
</div>
<div ref="tableContent"
class="table-content"
:class="{'no-footer': noFooter}"
@scroll="tableScroll"
@mouseover="mouseOver"
@mouseout="mouseOut">
<!-- Main Table -->
<table ref="systable"
id="systable"
style="table-layout: fixed; width: 0"
class="systable"
:class="{'no-number': noNumCol}"
ondragenter="event.preventDefault(); event.dataTransfer.dropEffect = 'none'"
ondragover="event.preventDefault(); event.dataTransfer.dropEffect = 'none'">
<colgroup>
<col v-if="!noNumCol" style="width:40px">
<col v-for="(item, p) in fields" v-show="!item.invisible" :key="p" :style="{width: item.width}">
<col v-if="vScroller.buttonHeight < vScroller.height" style="width:12px">
</colgroup>
<thead class="center-text">
<tr>
<th class="center-text first-col tl-setting"
:class="{hide: noNumCol}"
style="top: 0"
@mousedown.left="selectAllClick"
@contextmenu.prevent="settingClick">
<span style="width:100%">
<svg v-if="selectedCount>0" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-times-circle fa-w-16 fa-sm"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg>
<svg v-else aria-hidden="true" focusable="false" data-prefix="fas" data-icon="bars" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-bars fa-w-14 fa-sm"><path fill="currentColor" d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path></svg>
<!--
<svg v-if="processing" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="spinner" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-spinner fa-w-16 fa-spin fa-sm"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z"></path></svg>
<svg v-else aria-hidden="true" focusable="false" data-prefix="fas" data-icon="bars" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-bars fa-w-14 fa-sm"><path fill="currentColor" d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path></svg>
-->
</span>
</th>
<th v-for="(item, p) in fields"
v-show="!item.invisible"
:key="`th-${p}`"
:colspan="p === fields.length - 1 && vScroller.buttonHeight < vScroller.height ? 2: 1"
:class="{'sort-asc-sign': sortPos==p && sortDir==1,
'sort-des-sign': sortPos==p && sortDir==-1,
'sticky-column': item.sticky}"
:style="{left: item.left}"
@mousedown="headerClick($event, p)"
@contextmenu.prevent="panelFilterClick(item)">
<div :class="{'filter-sign': columnFilter[p]}">
<span :class="{'table-col-header': !noHeaderEdit}" v-html="headerLabel(item.label, item)"></span>
</div>
<div class="col-sep"
@mousedown="colSepMouseDown"
@mouseover="colSepMouseOver"
@mouseout="colSepMouseOut">
<div class="add-col-btn"> + </div>
</div>
</th>
</tr>
<tr :class="{hide: !filterRow}">
<td class="center-text first-col tl-filter"
:class="{hide: noNumCol}"
style="vertical-align: middle; padding: 0"
:style="{top: calCellTop2 + 'px'}"
@click="columnFilter = {}">
<span v-if="Object.keys(columnFilter).length > 0">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="eraser" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-eraser fa-w-16 fa-sm"><path fill="currentColor" d="M497.941 273.941c18.745-18.745 18.745-49.137 0-67.882l-160-160c-18.745-18.745-49.136-18.746-67.883 0l-256 256c-18.745 18.745-18.745 49.137 0 67.882l96 96A48.004 48.004 0 0 0 144 480h356c6.627 0 12-5.373 12-12v-40c0-6.627-5.373-12-12-12H355.883l142.058-142.059zm-302.627-62.627l137.373 137.373L265.373 416H150.628l-80-80 124.686-124.686z"></path></svg>
</span>
<!--
<svg v-if="selectedCount==table.length" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-times-circle fa-w-16 fa-sm"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg>
<svg v-else aria-hidden="true" focusable="false" data-prefix="fas" data-icon="check-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-check-circle fa-w-16 fa-sm"><path fill="currentColor" d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"></path></svg>
-->
</td>
<vue-excel-filter v-for="(item, p) in fields"
v-show="!item.invisible"
:ref="`filter-${item.name}`"
:colspan="p === fields.length - 1? 2: 1"
:key="`th2-${p}`"
v-model="columnFilter[p]"
:class="{'sticky-column': item.sticky}"
:style="{left: item.left}"
class="column-filter" />
</tr>
</thead>
<tbody @mousedown="mouseDown">
<tr v-if="localizedLabel.noRecordIndicator && pagingTable.length == 0">
<td colspan="100%" style="height:40px; vertical-align: middle; text-align: center"></td>
</tr>
<tr v-else
v-for="(record, rowPos) in pagingTable"
:key="rowPos"
:class="{select: typeof selected[pageTop + rowPos] !== 'undefined'}"
:style="rowStyle(record)">
<td class="center-text first-col"
:id="`rid-${record.$id}`"
:class="{
hide: noNumCol,
error: rowerr[`rid-${record.$id}`]
}"
:pos="rowPos"
@mouseover="numcolMouseOver"
@click="rowLabelClick">
<span v-html="recordLabel(pageTop + rowPos + 1, record)"></span>
</td>
<td v-for="(item, p) in fields"
v-show="!item.invisible"
:id="`id-${record.$id}-${item.name}`"
:cell-RC="`${rowPos}-${item.name}`"
:class="{
readonly: item.readonly,
error: errmsg[`id-${record.$id}-${item.name}`],
link: item.link,
select: item.options,
datepick: item.type == 'date',
'sticky-column': item.sticky
}"
:key="p"
:style="Object.assign(cellStyle(record, item), renderColumnCellStyle(item))"
@mouseover="cellMouseOver"
@mousemove="cellMouseMove">{{ item.toText(record[item.name]) }}</td>
<td v-if="vScroller.buttonHeight < vScroller.height" class="last-col"></td>
</tr>
</tbody>
<tfoot>
<tr v-show="pagingTable.length && summaryRow">
<td class="row-summary first-col"> </td>
<td v-for="(field, p) in fields"
v-show="!field.invisible"
class="row-summary"
:colspan="p === fields.length - 1 && vScroller.buttonHeight < vScroller.height ? 2: 1"
:class="{
'sticky-column': field.sticky,
'summary-column1': p+1 < fields.length && fields[p+1].summary,
'summary-column2': field.summary
}"
:key="`f${p}`"
:style="renderColumnCellStyle(field)"
>{{ summary[field.name] }}</td>
</tr>
</tfoot>
<slot></slot>
</table>
<!-- Tool Tip -->
<div v-show="tip" ref="tooltip" class="tool-tip">{{ tip }}</div>
<!-- Text Tip -->
<div v-show="textTip" ref="texttip" class="text-tip">{{ textTip }}</div>
<!-- Editor Square -->
<div v-show="focused" ref="inputSquare" class="input-square" @mousedown="inputSquareClick">
<div style="position: relative; height: 100%; padding: 2px 2px 1px">
<div class="rb-square" />
<textarea ref="inputBox"
id="inputBox"
class="input-box"
:style="{opacity: inputBoxShow}"
@blur="inputBoxBlur"
@mousemove="inputBoxMouseMove"
@mousedown="inputBoxMouseDown"
trim
autocomplete="off"
autocorrect="off"
autocompitaize="off"
:spellcheck="spellcheck"></textarea>
</div>
</div>
<!-- Date Picker -->
<div ref="dpContainer" v-show="showDatePicker" style="z-index:20; position:fixed">
<date-picker ref="datepicker" inline v-model="inputDateTime" @input="datepickerClick" valueType="format"></date-picker>
</div>
<!-- Waiting scene -->
<div v-show="processing" ref="frontdrop" class="front-drop">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="spinner" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-spinner fa-w-16 fa-spin fa-3x"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z"></path></svg>
</div>
</div>
<!-- Vertical Scroll Bar -->
<div v-show="vScroller.buttonHeight < vScroller.height"
ref="vScroll"
class="v-scroll"
:style="{top: `${vScroller.top}px`, height: `${vScroller.height}px`}"
@mousedown="vsMouseDown">
<div ref="vScrollButton"
class="v-scroll-button"
:style="{marginTop: `${vScroller.buttonTop}px`, height: `${vScroller.buttonHeight}px`}"
@mousedown="vsbMouseDown">
<div v-show="vScroller.runner" class="runner" v-html="vScroller.runner" />
</div>
</div>
<!-- Autocomplete List -->
<ul ref="autocomplete" v-show="focused && autocompleteInputs.length" class="autocomplete-results">
<li v-for="(item,i) in autocompleteInputs"
:key="i"
:class="{select: autocompleteSelect === i}"
@mousedown.left.prevent="inputAutocompleteText($event.target.textContent, $event)"
class="autocomplete-result">{{ item }}</li>
</ul>
<!-- Footer -->
<div ref="footer" class="footer center-text" :class="{hide: noFooter}" style="position:relative" @mousedown="ftMouseDown">
<div ref="hScroll" class="h-scroll" @mousedown="sbMouseDown" />
<span class="left-block"></span>
<span v-show="!noPaging" style="position: absolute; left: 46px">
<span v-html="localizedLabel.footerLeft(pageTop + 1, pageBottom, table.length)"></span>
</span>
<span v-show="!noPaging && pageBottom - pageTop < table.length">
<template v-if="processing">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="spinner" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-spinner fa-w-16 fa-spin fa-sm"><path fill="currentColor" d="M304 48c0 26.51-21.49 48-48 48s-48-21.49-48-48 21.49-48 48-48 48 21.49 48 48zm-48 368c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zm208-208c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.49-48-48-48zM96 256c0-26.51-21.49-48-48-48S0 229.49 0 256s21.49 48 48 48 48-21.49 48-48zm12.922 99.078c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.491-48-48-48zm294.156 0c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-26.509-21.49-48-48-48zM108.922 60.922c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48-21.491-48-48-48z"></path></svg>
<span v-html="localizedLabel.processing" />
</template>
<template v-else>
<a :class="{disabled: pageTop <= 0}" @mousedown="firstPage">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="step-backward" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-step-backward fa-w-14 fa-sm"><path fill="currentColor" d="M64 468V44c0-6.6 5.4-12 12-12h48c6.6 0 12 5.4 12 12v176.4l195.5-181C352.1 22.3 384 36.6 384 64v384c0 27.4-31.9 41.7-52.5 24.6L136 292.7V468c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12z"></path></svg>
<span v-html="localizedLabel.first" />
</a>
|
<a :class="{disabled: pageTop <= 0}" @mousedown="prevPage">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="backward" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-backward fa-w-16 fa-sm"><path fill="currentColor" d="M11.5 280.6l192 160c20.6 17.2 52.5 2.8 52.5-24.6V96c0-27.4-31.9-41.8-52.5-24.6l-192 160c-15.3 12.8-15.3 36.4 0 49.2zm256 0l192 160c20.6 17.2 52.5 2.8 52.5-24.6V96c0-27.4-31.9-41.8-52.5-24.6l-192 160c-15.3 12.8-15.3 36.4 0 49.2z"></path></svg>
<span v-html="localizedLabel.previous" />
</a>
|
<a :class="{disabled: pageTop + pageSize >= table.length}" @mousedown="nextPage">
<span v-html="localizedLabel.next" />
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="forward" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-forward fa-w-16 fa-sm"><path fill="currentColor" d="M500.5 231.4l-192-160C287.9 54.3 256 68.6 256 96v320c0 27.4 31.9 41.8 52.5 24.6l192-160c15.3-12.8 15.3-36.4 0-49.2zm-256 0l-192-160C31.9 54.3 0 68.6 0 96v320c0 27.4 31.9 41.8 52.5 24.6l192-160c15.3-12.8 15.3-36.4 0-49.2z"></path></svg>
</a>
|
<a :class="{disabled: pageTop + pageSize >= table.length}" @mousedown="lastPage">
<span v-html="localizedLabel.last" />
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="step-forward" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-step-forward fa-w-14 fa-sm"><path fill="currentColor" d="M384 44v424c0 6.6-5.4 12-12 12h-48c-6.6 0-12-5.4-12-12V291.6l-195.5 181C95.9 489.7 64 475.4 64 448V64c0-27.4 31.9-41.7 52.5-24.6L312 219.3V44c0-6.6 5.4-12 12-12h48c6.6 0 12 5.4 12 12z"></path></svg>
</a>
</template>
</span>
<span style="position: absolute; right: 6px">
<a :class="{disabled: !showSelectedOnly && selectedCount <= 1}" @mousedown="toggleSelectView">
<span v-html="localizedLabel.footerRight.selected" />
<span :style="{color: selectedCount>0 ? 'red': 'inherit'}">{{ selectedCount }}</span>
</a>
|
<a :class="{disabled: columnFilterString === '{}'}" @mousedown="toggleFilterView">
<span v-html="localizedLabel.footerRight.filtered" />
<span :style="{color: table.length !== filteredValue.length ? 'red': 'inherit'}">{{ table.length }}</span>
</a>
|
<a :class="{disabled: true}">
<span v-html="localizedLabel.footerRight.loaded" />
<span>{{ filteredValue.length }}</span>
</a>
</span>
</div>
<input type="file"
ref="importFile"
accept=".xlsx, .xls, xlsm, .csv"
style="position: absolute; top: 0; left: 0; width:0; height: 0; opacity:0; z-index:-1"
@keyup="componentTabInto"
@change="doImport" />
<panel-filter ref="panelFilter" :n-filter-count="nFilterCount" :localized-label="localizedLabel" />
<panel-setting ref="panelSetting" v-model="fields" :localized-label="localizedLabel" />
<panel-find ref="panelFind" :localized-label="localizedLabel" />
</div>
</div>
</template>
<script>
import VueExcelFilter from './VueExcelFilter.vue'
import PanelFilter from './PanelFilter.vue'
import PanelSetting from './PanelSetting.vue'
import PanelFind from './PanelFind.vue'
import DatePicker from 'vue2-datepicker'
import XLSX from 'xlsx'
import 'vue2-datepicker/index.css'
export default {
components: {
'vue-excel-filter': VueExcelFilter,
'panel-filter': PanelFilter,
'panel-setting': PanelSetting,
'panel-find': PanelFind,
'date-picker': DatePicker
},
props: {
disablePanelSetting: {
type: Boolean,
default() {
return false;
}
},
disablePanelFilter: {
type: Boolean,
default() {
return false;
}
},
value: {type: Array, default () {return []}},
rowStyle: {type: Function, default () {return {}}},
cellStyle: {type: Function, default () {return {}}},
headerLabel: {
type: Function,
default (label) {
return label
}
},
recordLabel: { // return the row header
type: Function,
default (pos) {
return pos
}
},
noFinding: {type: Boolean, default: false},
noFindingNext: {type: Boolean, default: false},
filterRow: {type: Boolean, default: false},
freeSelect: {type: Boolean, default: false},
noFooter: {type: Boolean, default: false},
noPaging: {type: Boolean, default: false},
noNumCol: {type: Boolean, default: false},
noMouseScroll: {type: Boolean, default: false},
page: {type: Number, default: 0}, // prefer page size, auto-cal if not provided
enterToSouth: {type: Boolean, default: false}, // default enter to south
nFilterCount: {type: Number, default: 1000}, // show top n values in filter dialog
height: {type: String, default: ''},
width: {type: String, default: '100%'},
wheelSensitivity: {type: Number, default: 30},
autocomplete: {type: Boolean, default: false}, // Default autocomplete of all columns
autocompleteCount: {type: Number, default: 50},
readonly: {type: Boolean, default: false},
readonlyStyle: {type: Object, default () {return {}}},
remember: {type: Boolean, default: false},
register: {type: Function, default: null},
allowAddCol: {type: Boolean, default: false},
noHeaderEdit: {type: Boolean, default: false},
addColumn: {type: Function, default: null},
spellcheck: {type: Boolean, default: false},
newIfBottom: {type: Boolean, default: false},
validate: {type: Function, default: null},
localizedLabel: {
type: Object,
default () {
return {
footerLeft: (top, bottom, total) => `Record ${top} to ${bottom} of ${total}`,
first: 'First',
previous: 'Previous',
next: 'Next',
last: 'Last',
footerRight: {
selected: 'Selected:',
filtered: 'Filtered:',
loaded: 'Loaded:'
},
processing: 'Processing',
tableSetting: 'Table Setting',
exportExcel: 'Export Excel',
importExcel: 'Import Excel',
back: 'Back',
reset: 'Default',
sortingAndFiltering: 'Sorting And Filtering',
sortAscending: 'Sort Ascending',
sortDescending: 'Sort Descending',
near: '≒ Near',
exactMatch: '= Exact Match',
notMatch: '≠ Not Match',
greaterThan: '> Greater Than',
greaterThanOrEqualTo: '≥ Greater Than or Equal To',
lessThan: '< Less Than',
lessThanOrEqualTo: '≤ Less Than Or Equal To',
regularExpression: '~ Regular Expression',
customFilter: 'Custom Filter',
listFirstNValuesOnly: n => `List first ${n} values only`,
apply: 'Apply',
noRecordIsRead: 'No record is read',
readonlyColumnDetected: 'Readonly column detected',
columnHasValidationError: (name, err) => `Column ${name} has validation error: ${err}`,
rowHasValidationError: (row, name, err) => `Row ${row} has validation error for column ${name}: ${err}`,
noMatchedColumnName: 'No matched column name',
invalidInputValue: 'Invalid input value',
missingKeyColumn: 'Missing key column',
noRecordIndicator: 'No record'
}
}
},
recordFilter: {
type: Function,
default () {
return true
}
}
},
data () {
const pageSize = this.noPaging ? 999999 : 20
const dataset = {
version: '1.3',
tableContent: null, // Table parent
systable: null, // TABLE dom node
colgroupTr: null, // colgroup TR dom node
labelTr: null, // THEAD label dom node
filterTr: null, // THEAD filter dom node
recordBody: null, // TBODY dom node
footer: null, // TFOOTER dom node
pageSize: pageSize,
pageTop: 0, // Current page top pos of [table] array
selected: {}, // selected storage in hash, key is the pos of [table] array
selectedCount: 0, // selected row count
prevSelect: -1, // previous select pos of [table] array
processing: false, // current general-purpose processing status
rowIndex: {}, // index of the record key to pos of [table] array
currentRecord: null, // focusing row content
currentRowPos: 0, // focusing array pos of [table] array
currentColPos: 0, // focusing pos of column/field
currentField: null, // focusing field object
currentCell: null,
inputBox: null,
inputBoxShow: 0,
inputSquare: null,
autocompleteInputs: [],
autocompleteSelect: -1,
errmsg: {},
rowerr: {},
tip: '',
textTip: '',
colHash: '',
fields: [],
focused: false,
mousein: false,
inputBoxChanged: false,
columnFilter: {}, // set filter storage in hash, key is the column pos
inputFind: '',
calCellLeft: 0,
calCellTop: 0,
calCellTop2: 29,
frontdrop: null, // frontdrop dom node
sortPos: 0, // Sort column position
sortDir: 0, // Sort direction, 1=Ascending, -1=Descending
redo: [], // redo log
lazyTimeout: {},
lazyBuffer: {},
hScroller: {},
vScroller: {},
leftMost: 0,
showDatePicker: false,
inputDateTime: new Date(),
table: [],
filteredValue: [],
lastFilterTime: '',
summaryRow: false,
summary: {},
showFilteredOnly: true,
showSelectedOnly: false
}
return dataset
},
computed: {
token () {
const id = Array.from(document.querySelectorAll('.vue-excel-editor')).indexOf(this.$el)
return `vue-excel-editor-${id}`
},
columnFilterString () {
Object.keys(this.columnFilter).forEach((key) => {
if (this.columnFilter[key].trim() === '') delete this.columnFilter[key]
})
return JSON.stringify(this.columnFilter)
},
pagingTable () {
return this.table.slice(this.pageTop, this.pageTop + this.pageSize)
},
pageBottom () {
if (this.filteredValue.length === 0) return 0
else return this.pageTop + this.pageSize > this.table.length ? this.table.length : this.pageTop + this.pageSize
},
setting: {
get () {
return null
},
set (setter) {
if (setter.fields) {
// ignore if fields counts are different
if (setter.fields.length !== this.fields.length) return
let valid = true
const newFields = setter.fields.map(local => {
const current = this.fields.find(f => f.name === local.name)
if (!current) valid = false
else {
if (typeof local.invisible !== 'undefined') current.invisible = local.invisible
if (typeof local.width !== 'undefined') current.width = local.width
if (typeof local.label !== 'undefined') current.label = local.label
}
return current
})
if (valid) {
this.fields = newFields
this.$forceUpdate()
}
}
}
}
},
watch: {
value () {
this.lazy(() => {
this.refresh()
if (this.pageTop > this.table.length)
this.lastPage()
})
},
columnFilterString () {
this.lastFilterTime = String(new Date().getTime() % 1e8)
this.processing = true
setTimeout(() => {
this.pageTop = 0
this.refresh()
this.processing = false
}, 0)
},
fields: {
handler () {
this.lazy(() => {
const setting = this.getSetting()
if (this.remember) localStorage[window.location.pathname + '.' + this.token] = JSON.stringify(setting)
this.$emit('setting', setting)
})
},
deep: true
},
processing (newVal) {
if (newVal) {
const rect = this.$el.children[0].getBoundingClientRect()
this.frontdrop.style.top = rect.top + 'px'
this.frontdrop.style.left = rect.left + 'px'
this.frontdrop.style.height = rect.height + 'px'
this.frontdrop.style.width = rect.width + 'px'
}
},
pageTop (newVal) {
this.$emit('page-changed', newVal, newVal + this.pageSize - 1)
},
pageSize (newVal) {
this.$emit('page-changed', this.pageTop, this.pageTop + newVal - 1)
}
},
beforeDestroy () {
window.removeEventListener('resize', this.winResize)
window.removeEventListener('paste', this.winPaste)
window.removeEventListener('keydown', this.winKeydown)
window.removeEventListener('keyup', this.winKeyup)
window.removeEventListener('scroll', this.winScroll)
window.removeEventListener('wheel', this.mousewheel)
},
mounted () {
this.editor = this.$refs.editor
this.tableContent = this.$refs.tableContent
this.systable = this.$refs.systable
this.colgroupTr = this.systable.children[0]
this.labelTr = this.systable.children[1].children[0]
this.filterTr = this.systable.children[1].children[1]
this.recordBody = this.systable.children[2]
this.footer = this.$refs.footer
this.inputSquare = this.$refs.inputSquare
this.inputBox = this.$refs.inputBox
this.frontdrop = this.$refs.frontdrop
if (this.height)
this.systable.parentNode.style.height = this.height
this.reset()
this.lazy(() => {
this.labelTr.children[0].style.height = this.labelTr.offsetHeight + 'px'
this.calCellTop2 = this.labelTr.offsetHeight
this.refreshPageSize()
this.tableContent.scrollTo(0, this.tableContent.scrollTop)
this.calStickyLeft()
}, 200)
if (ResizeObserver) new ResizeObserver(this.winResize).observe(this.tableContent)
window.addEventListener('resize', this.winResize)
window.addEventListener('paste', this.winPaste)
window.addEventListener('keydown', this.winKeydown)
window.addEventListener('keyup', this.winKeyup)
window.addEventListener('scroll', this.winScroll)
window.addEventListener('wheel', this.mousewheel, {passive: false})
if (this.remember) {
const saved = localStorage[window.location.pathname + '.' + this.token]
if (saved) {
const data = JSON.parse(saved)
if (data.colHash === this.colHash)
this.setting = data
}
}
},
methods: {
componentTabInto (e) {
if (e.keyCode === 9) {
if (!this.moveInputSquare(this.currentRowPos, this.currentColPos))
this.moveInputSquare(0, 0)
}
},
reset () {
this.errmsg = {}
this.redo = []
this.showFilteredOnly = true
this.showSelectedOnly = false
this.columnFilter = {}
this.sortPos = 0
this.sortDir = 0
this.inputFind = ''
this.pageTop = 0
this.selected = {}
this.selectedCount = 0
this.prevSelect = -1
this.processing = false
this.rowIndex = {}
this.refresh()
},
toggleSelectView (e) {
if (e) e.stopPropagation()
this.showSelectedOnly = !this.showSelectedOnly
this.firstPage()
return this.refresh()
},
toggleFilterView (e) {
if (e) e.stopPropagation()
this.showFilteredOnly = !this.showFilteredOnly
return this.refresh()
},
resetColumn () {
this.fields = []
//this.$slots.default.forEach(col => col.componentInstance? col.componentInstance.init() : 0)
this.tableContent.scrollTo(0, this.tableContent.scrollTop)
this.calStickyLeft()
},
registerColumn (field) {
let pos = this.fields.findIndex(item => item.pos > field.pos)
if (pos === -1) pos = this.fields.length
this.fields.splice(pos, 0, field)
if (this.register) this.register(field, pos)
if (field.register) field.register(field, pos)
if (field.summary) this.summaryRow = true
this.colHash = this.hashCode(this.version + JSON.stringify(this.fields))
},
insertColumn (pos) {
const colname = 'COL-' + Math.random().toString().slice(2,6)
let colDef = {
name: colname,
label: colname,
type: 'string',
width: '100px',
validate: null,
change: null,
link: null,
sort: null,
keyField: false,
sticky: false,
// tabStop: true,
allowKeys: null,
mandatory: false,
lengthLimit: 0,
autocomplete: this.autocomplete,
textTransform: null,
initStyle: 'left',
invisible: false,
readonly: this.readonly,
pos: 0,
options: null,
summary: null,
toValue: t => t,
toText: t => t,
register: null
}
if (this.addColumn) colDef = this.addColumn(colDef)
this.newColumn(colDef, pos)
},
newColumn (field, pos) {
this.fields.splice(pos, 0, field)
if (this.register) this.register(field, pos)
if (field.register) field.register(field, pos)
if (field.summary) this.summaryRow = true
this.colHash = this.hashCode(this.version + JSON.stringify(this.fields))
},
autoRegisterAllColumns (rows) {
// If no field is defined, this function will help to create all fields based on provided row sample argument
const widths = rows.slice(0, 25)
.reduce((t, v) => Object.keys(v).map((s, i) => !t || v[s].length > t[i]? v[s].length: t[i]), 0)
.map(v => Math.min(Math.max(v * 8.2, 55), 250))
Object.keys(rows[0]).forEach((col, i) => {
if (col === '$id') return
this.registerColumn({
name: col,
label: col,
type: widths[i]? 'string': 'number',
width: (widths[i]? widths[i]: 75) + 'px',
validate: null,
change: null,
link: null,
keyField: false,
sticky: false,
tabStop: true,
allowKeys: null,
mandatory: false,
lengthLimit: 0,
autocomplete: this.autocomplete,
initStyle: {textAlign: widths[i]? 'left': 'right'},
invisible: false,
readonly: this.readonly,
pos: 0,
options: null,
summary: null,
sort: null,
toValue: t => t,
toText: t => t,
register: null
})
})
},
refresh () {
// this.pageTop = 0
this.prevSelect = -1
if (this.fields.length === 0 && this.value.length && Object.keys(this.value[0])) {
this.autoRegisterAllColumns(this.value)
}
this.calTable()
this.refreshPageSize()
},
calTable () {
this.textTip = ''
// add unique key to each row if no key is provided
let seed = String(new Date().getTime() % 1e8)
this.value.forEach((rec,i) => {
if (!rec.$id) rec.$id = seed + '-' + ('000000' + i).slice(-7)
})
if (this.showFilteredOnly === false) {
this.table = this.value
}
else {
const filterColumnList = Object.keys(this.columnFilter)
const filter = {}
filterColumnList.forEach((k) => {
switch (true) {
case this.columnFilter[k].startsWith('<='):
filter[k] = {type: 1, value: this.columnFilter[k].slice(2).trim().toUpperCase()}
if (this.fields[k].type === 'number') filter[k].value = Number(filter[k].value)
break
case this.columnFilter[k].startsWith('<>'):
filter[k] = {type: 9, value: this.columnFilter[k].slice(2).trim().toUpperCase()}
break
case this.columnFilter[k].startsWith('<'):
filter[k] = {type: 2, value: this.columnFilter[k].slice(1).trim().toUpperCase()}
if (this.fields[k].type === 'number') filter[k].value = Number(filter[k].value)
break
case this.columnFilter[k].startsWith('>='):
filter[k] = {type: 3, value: this.columnFilter[k].slice(2).trim().toUpperCase()}
if (this.fields[k].type === 'number') filter[k].value = Number(filter[k].value)
break
case this.columnFilter[k].startsWith('>'):
filter[k] = {type: 4, value: this.columnFilter[k].slice(1).trim().toUpperCase()}
if (this.fields[k].type === 'number') filter[k].value = Number(filter[k].value)
break
case this.columnFilter[k].startsWith('='):
filter[k] = {type: 0, value: this.columnFilter[k].slice(1).trim().toUpperCase()}
break
case this.columnFilter[k].startsWith('*') && this.columnFilter[k].endsWith('*'):
filter[k] = {type: 5, value: this.columnFilter[k].slice(1).slice(0, -1).trim().toUpperCase()}
break
case this.columnFilter[k].startsWith('*') && !this.columnFilter[k].slice(1).includes('*'):
filter[k] = {type: 6, value: this.columnFilter[k].slice(1).trim().toUpperCase()}
break
case this.columnFilter[k].startsWith('~'):
filter[k] = {type: 8, value: this.columnFilter[k].slice(1).trim()}
break
case this.columnFilter[k].endsWith('*') && !this.columnFilter[k].slice(0, -1).includes('*'):
filter[k] = {type: 7, value: this.columnFilter[k].slice(0, -1).trim().toUpperCase()}
break
case this.columnFilter[k].includes('*') || this.columnFilter[k].includes('?'):
filter[k] = {type: 8, value: '^' + this.columnFilter[k].replace(/\*/g, '.*').replace(/\?/g, '.').trim() + '$'}
break
default:
filter[k] = {type: 5, value: this.columnFilter[k].trim().toUpperCase()}
break
}
})
this.filteredValue = this.value.filter(record => this.recordFilter(record))
if (filterColumnList.length === 0)
this.table = this.filteredValue
else {
this.table = this.filteredValue.filter((record) => {
// Record is created after the filter time
if (record.$id > this.lastFilterTime) return true
// Assume new record contains § in any of the key fields
/*
const isNew = this.fields.filter((field) => {
return field.keyField && record[field.name] && record[field.name].startsWith('§')
}).length > 0
if (isNew) return true // Always show new record in filter mode
*/
const content = {}
filterColumnList.forEach((k) => {
const val = record[this.fields[k].name]
if (this.fields[k].type === 'number' && filter[k].type <= 4)
content[k] = val
else
content[k] = typeof val === 'undefined' || val === null ? '' : String(val).toUpperCase()
})
for (let i = 0; i < filterColumnList.length; i++) {
const k = filterColumnList[i]
switch (filter[k].type) {
case 0:
if (`${content[k]}` !== `${filter[k].value}`) return false
break
case 1:
if (filter[k].value < content[k]) return false
break
case 2:
if (filter[k].value <= content[k]) return false
break
case 3:
if (filter[k].value > content[k]) return false
break
case 4:
if (filter[k].value >= content[k]) return false
break
case 5:
if (!content[k].includes(filter[k].value)) return false
break
case 6:
if (!content[k].endsWith(filter[k].value)) return false
break
case 7:
if (!content[k].startsWith(filter[k].value)) return false
break
case 8:
if (!new RegExp(filter[k].value, 'i').test(content[k])) return false
break
case 9:
if (`${content[k]}` === `${filter[k].value}`) return false
break
}
}
return true
})
}
}
this.reviseSelectedAfterTableChange()
if (this.showSelectedOnly) {
this.table = this.table.filter((rec, i) => this.selected[i])
this.reviseSelectedAfterTableChange()
}
this.calSummary()
},
calStickyLeft () {
let left = 0, n = 0
this.leftMost = -1
// this.tableContent.scrollTo(0, this.tableContent.scrollTop)
Array.from(this.labelTr.children).forEach(th => {
left += th.offsetWidth
const field = this.fields[n++]
if (field) {
if (field.sticky) {
field.left = left + 'px'
this.leftMost = -1 // Reset the leftMost, so it will equal to the next non-sticky col
}
else if (this.leftMost === -1) this.leftMost = left
}
})
this.$forceUpdate()
},
renderColumnCellStyle (field) {
let result = field.initStyle
if (field.readonly) result = Object.assign(result, this.readonlyStyle)
if (field.left) result = Object.assign(result, {left: field.left})
return result
},
localeDate (d) {
if (typeof d === 'undefined') d = new Date()
const pad = n => n < 10 ? '0'+n : n;
return d.getFullYear() + '-'
+ pad(d.getMonth() + 1) + '-'
+ pad(d.getDate()) + ' '
+ pad(d.getHours()) + ':'
+ pad(d.getMinutes()) + ':'
+ pad(d.getSeconds())
},
calSummary (name) {
this.fields.forEach(field => {
if (!field.summary) return
const i = field.name
if (name && name !== i) return
let result = ''
const currentTick = new Date().getTime()
const currentDateTimeSec = this.localeDate()
const currentDateTime = currentDateTimeSec.slice(0, 19)
const currentDate = currentDateTimeSec.slice(0, 10)
switch(field.summary) {
case 'sum':
result = this.table.reduce((a, b) => (a + Number(b[i] ? b[i] : 0)), 0)
result = Number(Math.round(result + 'e+5') + 'e-5') // solve the infinite .9 issue of javascript
break
case 'avg':
result = this.table.reduce((a, b) => (a + Number(b[i] ? b[i] : 0)), 0) / this.table.length
result = Number(Math.round(result + 'e+5') + 'e-5') // solve the infinite .9 issue of javascript
break
case 'max':
result = this.table.reduce((a, b) => (a > b[i] ? a : b[i]), Number.MIN_VALUE)
break
case 'min':
result = this.table.reduce((a, b) => (a < b[i] ? a : b[i]), Number.MAX_VALUE)
break
case 'count':
switch(field.type) {
case 'checkYN':
result = this.table.reduce((a, b) => (a + (b[i] === 'Y' ? 1 : 0)), 0)
break
case 'check10':
result = this.table.reduce((a, b) => (a + (b[i] === '1' ? 1 : 0)), 0)
break
case 'checkTF':
result = this.table.reduce((a, b) => (a + (b[i] === 'T' ? 1 : 0)), 0)
break
case 'date':
result = this.table.reduce((a, b) => (a + (b[i] >= currentDate ? 1 : 0)), 0)
this.summary[i] = result
return
case 'datetime':
result = this.table.reduce((a, b) => (a + (b[i] >= currentDateTime ? 1 : 0)), 0)
this.summary[i] = result
return
case 'datetimesec':
result = this.table.reduce((a, b) => (a + (b[i] >= currentDateTimeSec ? 1 : 0)), 0)
this.summary[i] = result
return
case 'datetick':
case 'datetimetick':
case 'datetimesectick':
result = this.table.reduce((a, b) => (a + (b[i] >= currentTick ? 1 : 0)), 0)
this.summary[i] = result
return
default:
result = this.table.reduce((a, b) => (a + (b[i]? 1 : 0)), 0)
break
}
break
}
if (field.type === 'number' && isNaN(result)) return
this.summary[i] = field.toText(result)
})
},
getKeys (rec) {
if (!rec) rec = this.currentRecord
const key = this.fields.filter(field => field.keyField).map(field => rec[field.name])
if (key.length && key.join() !== '') return key
return [rec.$id]
},
getFieldByName (name) {
return this.fields.find(f => f.name === name)
},
getFieldByLabel (label) {
return this.fields.find(f => f.label === label)
},
/* *** Customization **************************************************************************************
*/
setFilter(name, filterText) {
const ref = this.$refs[`filter-${name}`][0]
ref.$el.textContent = filterText