stk-table-vue 0.2.3 → 0.2.6
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/README.md +48 -5
- package/lib/src/StkTable/StkTable.vue.d.ts +24 -4
- package/lib/src/StkTable/index.d.ts +1 -0
- package/lib/src/StkTable/types/index.d.ts +11 -1
- package/lib/src/StkTable/useFixedStyle.d.ts +3 -3
- package/lib/src/StkTable/useVirtualScroll.d.ts +3 -2
- package/lib/src/StkTable/utils.d.ts +3 -1
- package/lib/stk-table-vue.js +178 -96
- package/package.json +5 -5
- package/src/StkTable/StkTable.vue +58 -24
- package/src/StkTable/types/index.ts +11 -1
- package/src/StkTable/useFixedStyle.ts +49 -28
- package/src/StkTable/useHighlight.ts +6 -3
- package/src/StkTable/useKeyboardArrowScroll.ts +8 -4
- package/src/StkTable/useVirtualScroll.ts +42 -11
- package/src/StkTable/utils.ts +66 -41
package/lib/stk-table-vue.js
CHANGED
|
@@ -70,23 +70,35 @@ function useAutoResize({ tableContainer, initVirtualScroll, props, debounceMs })
|
|
|
70
70
|
}, debounceMs);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function isEmptyValue(val, isNumber) {
|
|
74
|
+
let isEmpty = val === null || val === "";
|
|
75
|
+
if (isNumber) {
|
|
76
|
+
isEmpty || (isEmpty = typeof val === "boolean" || Number.isNaN(+val));
|
|
77
|
+
}
|
|
78
|
+
return isEmpty;
|
|
79
|
+
}
|
|
80
|
+
function insertToOrderedArray(sortState, newItem, targetArray, sortConfig = {}) {
|
|
74
81
|
const { dataIndex, order } = sortState;
|
|
82
|
+
sortConfig = { emptyToBottom: false, ...sortConfig };
|
|
75
83
|
let { sortType } = sortState;
|
|
76
84
|
if (!sortType)
|
|
77
85
|
sortType = typeof newItem[dataIndex];
|
|
86
|
+
const isNumber = sortType === "number";
|
|
78
87
|
const data = [...targetArray];
|
|
79
88
|
if (!order) {
|
|
80
89
|
data.unshift(newItem);
|
|
81
90
|
return data;
|
|
82
91
|
}
|
|
92
|
+
if (sortConfig.emptyToBottom && isEmptyValue(data)) {
|
|
93
|
+
data.push(newItem);
|
|
94
|
+
}
|
|
83
95
|
let sIndex = 0;
|
|
84
96
|
let eIndex = data.length - 1;
|
|
85
97
|
const targetVal = newItem[dataIndex];
|
|
86
98
|
while (sIndex <= eIndex) {
|
|
87
99
|
const midIndex = Math.floor((sIndex + eIndex) / 2);
|
|
88
100
|
const midVal = data[midIndex][dataIndex];
|
|
89
|
-
const compareRes = strCompare(midVal, targetVal,
|
|
101
|
+
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
90
102
|
if (compareRes === 0) {
|
|
91
103
|
sIndex = midIndex;
|
|
92
104
|
break;
|
|
@@ -105,17 +117,21 @@ function insertToOrderedArray(sortState, newItem, targetArray) {
|
|
|
105
117
|
data.splice(sIndex, 0, newItem);
|
|
106
118
|
return data;
|
|
107
119
|
}
|
|
108
|
-
function strCompare(a, b,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return -1;
|
|
116
|
-
} else {
|
|
120
|
+
function strCompare(a, b, isNumber, localeCompare = false) {
|
|
121
|
+
let _a = a;
|
|
122
|
+
let _b = b;
|
|
123
|
+
if (isNumber) {
|
|
124
|
+
_a = +a;
|
|
125
|
+
_b = +b;
|
|
126
|
+
} else if (localeCompare) {
|
|
117
127
|
return String(a).localeCompare(b);
|
|
118
128
|
}
|
|
129
|
+
if (_a > _b)
|
|
130
|
+
return 1;
|
|
131
|
+
else if (_a === _b)
|
|
132
|
+
return 0;
|
|
133
|
+
else
|
|
134
|
+
return -1;
|
|
119
135
|
}
|
|
120
136
|
function separatedData(sortOption, targetDataSource, isNumber) {
|
|
121
137
|
const emptyArr = [];
|
|
@@ -123,10 +139,7 @@ function separatedData(sortOption, targetDataSource, isNumber) {
|
|
|
123
139
|
for (let i = 0; i < targetDataSource.length; i++) {
|
|
124
140
|
const row = targetDataSource[i];
|
|
125
141
|
const sortField = sortOption.sortField || sortOption.dataIndex;
|
|
126
|
-
|
|
127
|
-
if (isNumber) {
|
|
128
|
-
isEmpty || (isEmpty = typeof row[sortField] === "boolean" || Number.isNaN(+row[sortField]));
|
|
129
|
-
}
|
|
142
|
+
const isEmpty = isEmptyValue(row[sortField], isNumber);
|
|
130
143
|
if (isEmpty) {
|
|
131
144
|
emptyArr.push(row);
|
|
132
145
|
} else {
|
|
@@ -154,25 +167,16 @@ function tableSort(sortOption, order, dataSource, sortConfig = {}) {
|
|
|
154
167
|
if (!sortType)
|
|
155
168
|
sortType = typeof dataSource[0][sortField];
|
|
156
169
|
const [valueArr, emptyArr] = separatedData(sortOption, targetDataSource, sortType === "number");
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
targetDataSource = [...emptyArr, ...valueArr];
|
|
161
|
-
} else {
|
|
162
|
-
valueArr.sort((a, b) => +b[sortField] - +a[sortField]);
|
|
163
|
-
targetDataSource = [...valueArr, ...emptyArr];
|
|
164
|
-
}
|
|
170
|
+
const isNumber = sortType === "number";
|
|
171
|
+
if (order === "asc") {
|
|
172
|
+
valueArr.sort((a, b) => strCompare(a[sortField], b[sortField], isNumber, sortConfig.stringLocaleCompare));
|
|
165
173
|
} else {
|
|
166
|
-
|
|
167
|
-
valueArr.sort((a, b) => String(a[sortField]).localeCompare(b[sortField]));
|
|
168
|
-
targetDataSource = [...emptyArr, ...valueArr];
|
|
169
|
-
} else {
|
|
170
|
-
valueArr.sort((a, b) => String(a[sortField]).localeCompare(b[sortField]) * -1);
|
|
171
|
-
targetDataSource = [...valueArr, ...emptyArr];
|
|
172
|
-
}
|
|
174
|
+
valueArr.sort((a, b) => strCompare(b[sortField], a[sortField], isNumber, sortConfig.stringLocaleCompare));
|
|
173
175
|
}
|
|
174
|
-
if (sortConfig.emptyToBottom) {
|
|
176
|
+
if (order === "desc" || sortConfig.emptyToBottom) {
|
|
175
177
|
targetDataSource = [...valueArr, ...emptyArr];
|
|
178
|
+
} else {
|
|
179
|
+
targetDataSource = [...emptyArr, ...valueArr];
|
|
176
180
|
}
|
|
177
181
|
}
|
|
178
182
|
return targetDataSource;
|
|
@@ -188,10 +192,18 @@ function howDeepTheHeader(arr, level = 1) {
|
|
|
188
192
|
return Math.max(...levels);
|
|
189
193
|
}
|
|
190
194
|
function getColWidth(col) {
|
|
191
|
-
|
|
192
|
-
|
|
195
|
+
const val = (col == null ? void 0 : col.width) ?? Default_Col_Width;
|
|
196
|
+
if (typeof val === "number") {
|
|
197
|
+
return Math.floor(val);
|
|
198
|
+
}
|
|
199
|
+
return parseInt(val);
|
|
200
|
+
}
|
|
201
|
+
function getColWidthStr(col, key = "width") {
|
|
202
|
+
const val = col == null ? void 0 : col[key];
|
|
203
|
+
if (typeof val === "number") {
|
|
204
|
+
return val + "px";
|
|
193
205
|
}
|
|
194
|
-
return
|
|
206
|
+
return val;
|
|
195
207
|
}
|
|
196
208
|
function useColResize({
|
|
197
209
|
tableContainer,
|
|
@@ -371,36 +383,54 @@ function useFixedCol({ props, tableHeaderLast, tableContainer }) {
|
|
|
371
383
|
updateFixedShadow
|
|
372
384
|
};
|
|
373
385
|
}
|
|
374
|
-
function useFixedStyle({
|
|
386
|
+
function useFixedStyle({
|
|
387
|
+
props,
|
|
388
|
+
tableHeaders,
|
|
389
|
+
virtualScroll,
|
|
390
|
+
virtualScrollX,
|
|
391
|
+
virtualX_on,
|
|
392
|
+
virtualX_offsetRight
|
|
393
|
+
}) {
|
|
375
394
|
const fixedColumnsPositionStore = computed(() => {
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
395
|
+
const colKeyStore = {};
|
|
396
|
+
const refStore = /* @__PURE__ */ new WeakMap();
|
|
397
|
+
tableHeaders.value.forEach((cols) => {
|
|
398
|
+
let left = 0;
|
|
399
|
+
let rightStartIndex = 0;
|
|
400
|
+
for (let i = 0; i < cols.length; i++) {
|
|
401
|
+
const item = cols[i];
|
|
402
|
+
if (item.fixed === "left") {
|
|
403
|
+
if (item.dataIndex) {
|
|
404
|
+
colKeyStore[item.dataIndex] = left;
|
|
405
|
+
} else {
|
|
406
|
+
refStore.set(item, left);
|
|
407
|
+
}
|
|
408
|
+
left += getColWidth(item);
|
|
409
|
+
}
|
|
410
|
+
if (!rightStartIndex && item.fixed === "right") {
|
|
411
|
+
rightStartIndex = i;
|
|
412
|
+
}
|
|
388
413
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
414
|
+
let right = 0;
|
|
415
|
+
for (let i = cols.length - 1; i >= rightStartIndex; i--) {
|
|
416
|
+
const item = cols[i];
|
|
417
|
+
if (item.fixed === "right") {
|
|
418
|
+
if (item.dataIndex) {
|
|
419
|
+
colKeyStore[item.dataIndex] = right;
|
|
420
|
+
} else {
|
|
421
|
+
refStore.set(item, right);
|
|
422
|
+
}
|
|
423
|
+
right += getColWidth(item);
|
|
424
|
+
}
|
|
396
425
|
}
|
|
397
|
-
}
|
|
398
|
-
return
|
|
426
|
+
});
|
|
427
|
+
return { refStore, colKeyStore };
|
|
399
428
|
});
|
|
400
429
|
function getFixedStyle(tagType, col, depth = 0) {
|
|
401
|
-
const { fixed
|
|
430
|
+
const { fixed } = col;
|
|
402
431
|
const isFixedLeft = fixed === "left";
|
|
403
432
|
const style = {};
|
|
433
|
+
const { colKeyStore, refStore } = fixedColumnsPositionStore.value;
|
|
404
434
|
if (Is_Legacy_Mode) {
|
|
405
435
|
style.position = "relative";
|
|
406
436
|
} else {
|
|
@@ -427,10 +457,11 @@ function useFixedStyle({ props, tableHeaderLast, virtualScroll, virtualScrollX,
|
|
|
427
457
|
style.right = `${virtualX_offsetRight.value}px`;
|
|
428
458
|
}
|
|
429
459
|
} else {
|
|
460
|
+
const lr = (col.dataIndex ? colKeyStore[col.dataIndex] : refStore.get(col)) + "px";
|
|
430
461
|
if (isFixedLeft) {
|
|
431
|
-
style.left =
|
|
462
|
+
style.left = lr;
|
|
432
463
|
} else {
|
|
433
|
-
style.right =
|
|
464
|
+
style.right = lr;
|
|
434
465
|
}
|
|
435
466
|
}
|
|
436
467
|
}
|
|
@@ -444,9 +475,9 @@ const HIGHLIGHT_ROW_CLASS = "highlight-row";
|
|
|
444
475
|
const HIGHLIGHT_CELL_CLASS = "highlight-cell";
|
|
445
476
|
function useHighlight({ props, tableContainer }) {
|
|
446
477
|
const highlightRowStore = ref({});
|
|
447
|
-
const highlightFrom = Highlight_Color[props.theme].from;
|
|
448
|
-
const highlightTo = Highlight_Color[props.theme].to;
|
|
449
|
-
const highlightInter = computed(() => interpolateRgb(highlightFrom, highlightTo));
|
|
478
|
+
const highlightFrom = computed(() => Highlight_Color[props.theme].from);
|
|
479
|
+
const highlightTo = computed(() => Highlight_Color[props.theme].to);
|
|
480
|
+
const highlightInter = computed(() => interpolateRgb(highlightFrom.value, highlightTo.value));
|
|
450
481
|
const highlightDimRowKeys = /* @__PURE__ */ new Set();
|
|
451
482
|
const highlightDimRowsTimeout = /* @__PURE__ */ new Map();
|
|
452
483
|
const highlightDimCellsTimeout = /* @__PURE__ */ new Map();
|
|
@@ -468,6 +499,7 @@ function useHighlight({ props, tableContainer }) {
|
|
|
468
499
|
highlightDimRowKeys.delete(rowKeyValue);
|
|
469
500
|
}
|
|
470
501
|
});
|
|
502
|
+
highlightRowStore.value = { ...highlightRowStore.value };
|
|
471
503
|
if (highlightDimRowKeys.size > 0) {
|
|
472
504
|
recursion();
|
|
473
505
|
} else {
|
|
@@ -569,10 +601,11 @@ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll,
|
|
|
569
601
|
if (!isMouseOver)
|
|
570
602
|
return;
|
|
571
603
|
e.preventDefault();
|
|
572
|
-
const { scrollTop, rowHeight,
|
|
604
|
+
const { scrollTop, rowHeight, containerHeight } = virtualScroll.value;
|
|
573
605
|
const { scrollLeft } = virtualScrollX.value;
|
|
574
606
|
const { headless, headerRowHeight } = props;
|
|
575
607
|
const headerHeight = headless ? 0 : tableHeaders.value.length * (headerRowHeight || rowHeight);
|
|
608
|
+
const bodyPageSize = Math.floor((containerHeight - headerHeight) / rowHeight);
|
|
576
609
|
if (e.code === SCROLL_CODES[0]) {
|
|
577
610
|
scrollTo(scrollTop - rowHeight, null);
|
|
578
611
|
} else if (e.code === SCROLL_CODES[1]) {
|
|
@@ -582,9 +615,9 @@ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll,
|
|
|
582
615
|
} else if (e.code === SCROLL_CODES[3]) {
|
|
583
616
|
scrollTo(null, scrollLeft - rowHeight);
|
|
584
617
|
} else if (e.code === SCROLL_CODES[4]) {
|
|
585
|
-
scrollTo(scrollTop - rowHeight *
|
|
618
|
+
scrollTo(scrollTop - rowHeight * bodyPageSize + headerHeight, null);
|
|
586
619
|
} else if (e.code === SCROLL_CODES[5]) {
|
|
587
|
-
scrollTo(scrollTop + rowHeight *
|
|
620
|
+
scrollTo(scrollTop + rowHeight * bodyPageSize - headerHeight, null);
|
|
588
621
|
}
|
|
589
622
|
}
|
|
590
623
|
function handleMouseEnter() {
|
|
@@ -650,7 +683,13 @@ function useThDrag({ props, emits }) {
|
|
|
650
683
|
};
|
|
651
684
|
}
|
|
652
685
|
const VUE2_SCROLL_TIMEOUT_MS = 200;
|
|
653
|
-
function useVirtualScroll({
|
|
686
|
+
function useVirtualScroll({
|
|
687
|
+
props,
|
|
688
|
+
tableContainer,
|
|
689
|
+
dataSourceCopy,
|
|
690
|
+
tableHeaderLast,
|
|
691
|
+
tableHeaders
|
|
692
|
+
}) {
|
|
654
693
|
const virtualScroll = ref({
|
|
655
694
|
containerHeight: 0,
|
|
656
695
|
rowHeight: props.rowHeight,
|
|
@@ -728,11 +767,13 @@ function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLa
|
|
|
728
767
|
} else {
|
|
729
768
|
containerHeight = offsetHeight || Default_Table_Height;
|
|
730
769
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
770
|
+
const { headless, headerRowHeight } = props;
|
|
771
|
+
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
772
|
+
if (!headless) {
|
|
773
|
+
const headerToBodyRowHeightCount = Math.floor(tableHeaders.value.length * (headerRowHeight || rowHeight) / rowHeight);
|
|
774
|
+
pageSize -= headerToBodyRowHeightCount;
|
|
775
|
+
}
|
|
776
|
+
Object.assign(virtualScroll.value, { containerHeight, pageSize });
|
|
736
777
|
updateVirtualScrollY(scrollTop);
|
|
737
778
|
}
|
|
738
779
|
function initVirtualScrollX() {
|
|
@@ -749,9 +790,27 @@ function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLa
|
|
|
749
790
|
let vue2ScrollYTimeout = null;
|
|
750
791
|
function updateVirtualScrollY(sTop = 0) {
|
|
751
792
|
const { rowHeight, pageSize, scrollTop, startIndex: oldStartIndex } = virtualScroll.value;
|
|
752
|
-
|
|
753
|
-
|
|
793
|
+
virtualScroll.value.scrollTop = sTop;
|
|
794
|
+
let startIndex = Math.floor(sTop / rowHeight);
|
|
795
|
+
if (props.stripe) {
|
|
796
|
+
startIndex -= 1;
|
|
797
|
+
}
|
|
798
|
+
if (startIndex < 0) {
|
|
799
|
+
startIndex = 0;
|
|
800
|
+
}
|
|
801
|
+
if (props.stripe && startIndex !== 0) {
|
|
802
|
+
const scrollRows = Math.abs(oldStartIndex - startIndex);
|
|
803
|
+
if (scrollRows < 2) {
|
|
804
|
+
return;
|
|
805
|
+
} else if (scrollRows % 2) {
|
|
806
|
+
startIndex -= 1;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
754
809
|
let endIndex = startIndex + pageSize;
|
|
810
|
+
if (props.stripe) {
|
|
811
|
+
endIndex += 2;
|
|
812
|
+
}
|
|
813
|
+
const offsetTop = startIndex * rowHeight;
|
|
755
814
|
if (endIndex > dataSourceCopy.value.length) {
|
|
756
815
|
endIndex = dataSourceCopy.value.length;
|
|
757
816
|
}
|
|
@@ -761,12 +820,11 @@ function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLa
|
|
|
761
820
|
if (!props.optimizeVue2Scroll || sTop <= scrollTop || Math.abs(oldStartIndex - startIndex) >= pageSize) {
|
|
762
821
|
Object.assign(virtualScroll.value, {
|
|
763
822
|
startIndex,
|
|
764
|
-
offsetTop,
|
|
765
823
|
endIndex,
|
|
766
|
-
|
|
824
|
+
offsetTop
|
|
767
825
|
});
|
|
768
826
|
} else {
|
|
769
|
-
|
|
827
|
+
virtualScroll.value.endIndex = endIndex;
|
|
770
828
|
vue2ScrollYTimeout = window.setTimeout(() => {
|
|
771
829
|
Object.assign(virtualScroll.value, { startIndex, offsetTop });
|
|
772
830
|
}, VUE2_SCROLL_TIMEOUT_MS);
|
|
@@ -897,7 +955,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
897
955
|
dataSource: { default: () => [] },
|
|
898
956
|
rowKey: { type: [String, Number, Function], default: "" },
|
|
899
957
|
colKey: { type: [String, Number, Function], default: "dataIndex" },
|
|
900
|
-
emptyCellText: { default: "--" },
|
|
958
|
+
emptyCellText: { type: [String, Function], default: "--" },
|
|
901
959
|
noDataFull: { type: Boolean, default: false },
|
|
902
960
|
showNoData: { type: Boolean, default: true },
|
|
903
961
|
sortRemote: { type: Boolean, default: false },
|
|
@@ -913,8 +971,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
913
971
|
fixedColShadow: { type: Boolean, default: false },
|
|
914
972
|
optimizeVue2Scroll: { type: Boolean, default: false },
|
|
915
973
|
sortConfig: { default: () => ({
|
|
916
|
-
emptyToBottom: false
|
|
917
|
-
|
|
974
|
+
emptyToBottom: false,
|
|
975
|
+
stringLocaleCompare: true
|
|
976
|
+
}) },
|
|
977
|
+
hideHeaderTitle: { type: [Boolean, Array], default: false }
|
|
918
978
|
},
|
|
919
979
|
emits: ["sort-change", "row-click", "current-change", "row-dblclick", "header-row-menu", "row-menu", "cell-click", "header-cell-click", "scroll", "scroll-x", "col-order-change", "th-drag-start", "th-drop", "update:columns"],
|
|
920
980
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
@@ -931,6 +991,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
931
991
|
const tableHeaders = ref([]);
|
|
932
992
|
const tableHeaderLast = ref([]);
|
|
933
993
|
const dataSourceCopy = shallowRef([...props.dataSource]);
|
|
994
|
+
const getEmptyCellText = computed(() => {
|
|
995
|
+
if (typeof props.emptyCellText === "string") {
|
|
996
|
+
return () => props.emptyCellText;
|
|
997
|
+
} else {
|
|
998
|
+
return (col, row) => props.emptyCellText({ row, col });
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
934
1001
|
const rowKeyGenStore = /* @__PURE__ */ new WeakMap();
|
|
935
1002
|
const { isColResizing, onThResizeMouseDown } = useColResize({
|
|
936
1003
|
props,
|
|
@@ -955,10 +1022,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
955
1022
|
initVirtualScrollX,
|
|
956
1023
|
updateVirtualScrollY,
|
|
957
1024
|
updateVirtualScrollX
|
|
958
|
-
} = useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast });
|
|
1025
|
+
} = useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast, tableHeaders });
|
|
959
1026
|
const { getFixedStyle } = useFixedStyle({
|
|
960
1027
|
props,
|
|
961
|
-
|
|
1028
|
+
tableHeaders,
|
|
962
1029
|
virtualScroll,
|
|
963
1030
|
virtualScrollX,
|
|
964
1031
|
virtualX_on,
|
|
@@ -1021,8 +1088,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1021
1088
|
function dealDefaultSorter() {
|
|
1022
1089
|
if (!props.sortConfig.defaultSort)
|
|
1023
1090
|
return;
|
|
1024
|
-
const { dataIndex, order } = props.sortConfig.defaultSort;
|
|
1025
|
-
setSorter(dataIndex, order);
|
|
1091
|
+
const { dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
|
|
1092
|
+
setSorter(dataIndex, order, { force: false, silent });
|
|
1026
1093
|
}
|
|
1027
1094
|
function dealColumns() {
|
|
1028
1095
|
tableHeaders.value = [];
|
|
@@ -1038,17 +1105,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1038
1105
|
tableHeaders.value[depth] = [];
|
|
1039
1106
|
}
|
|
1040
1107
|
let allChildrenLen = 0;
|
|
1108
|
+
let allChildrenWidthSum = 0;
|
|
1041
1109
|
arr.forEach((col) => {
|
|
1042
1110
|
col.__PARENT__ = parent;
|
|
1043
1111
|
let colChildrenLen = 1;
|
|
1112
|
+
let colWidth = 0;
|
|
1044
1113
|
if (col.children) {
|
|
1045
|
-
|
|
1114
|
+
const [len, widthSum] = flat(
|
|
1046
1115
|
col.children,
|
|
1047
1116
|
col,
|
|
1048
1117
|
depth + 1
|
|
1049
1118
|
/* , col.fixed */
|
|
1050
1119
|
);
|
|
1120
|
+
colChildrenLen = len;
|
|
1121
|
+
colWidth = widthSum;
|
|
1051
1122
|
} else {
|
|
1123
|
+
colWidth = getColWidth(col);
|
|
1052
1124
|
tempHeaderLast.push(col);
|
|
1053
1125
|
}
|
|
1054
1126
|
tableHeaders.value[depth].push(col);
|
|
@@ -1060,9 +1132,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1060
1132
|
if (colSpan !== 1) {
|
|
1061
1133
|
col.colSpan = colSpan;
|
|
1062
1134
|
}
|
|
1135
|
+
if (!props.fixedMode && col.width === void 0) {
|
|
1136
|
+
col.width = colWidth + "px";
|
|
1137
|
+
}
|
|
1063
1138
|
allChildrenLen += colChildrenLen;
|
|
1139
|
+
allChildrenWidthSum += colWidth;
|
|
1064
1140
|
});
|
|
1065
|
-
return allChildrenLen;
|
|
1141
|
+
return [allChildrenLen, allChildrenWidthSum];
|
|
1066
1142
|
}
|
|
1067
1143
|
flat(copyColumn, null);
|
|
1068
1144
|
tableHeaderLast.value = tempHeaderLast;
|
|
@@ -1082,17 +1158,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1082
1158
|
return typeof props.colKey === "function" ? props.colKey(col) : col[props.colKey];
|
|
1083
1159
|
}
|
|
1084
1160
|
function getColWidthStyle(col) {
|
|
1161
|
+
const width = getColWidthStr(col);
|
|
1162
|
+
const minWidth = getColWidthStr(col, "minWidth");
|
|
1163
|
+
const maxWidth = getColWidthStr(col, "maxWidth");
|
|
1085
1164
|
const style = {
|
|
1086
|
-
width
|
|
1087
|
-
minWidth:
|
|
1088
|
-
maxWidth:
|
|
1165
|
+
width,
|
|
1166
|
+
minWidth: minWidth ?? width,
|
|
1167
|
+
maxWidth: maxWidth ?? width
|
|
1089
1168
|
};
|
|
1090
1169
|
if (props.colResizable) {
|
|
1091
|
-
style.minWidth =
|
|
1092
|
-
style.maxWidth =
|
|
1093
|
-
} else {
|
|
1094
|
-
style.minWidth = col.minWidth === void 0 ? col.width : col.minWidth;
|
|
1095
|
-
style.maxWidth = col.maxWidth === void 0 ? col.width : col.maxWidth;
|
|
1170
|
+
style.minWidth = width;
|
|
1171
|
+
style.maxWidth = width;
|
|
1096
1172
|
}
|
|
1097
1173
|
return style;
|
|
1098
1174
|
}
|
|
@@ -1108,6 +1184,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1108
1184
|
}
|
|
1109
1185
|
return style;
|
|
1110
1186
|
}
|
|
1187
|
+
function getHeaderTitle(col) {
|
|
1188
|
+
if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(col.dataIndex)) {
|
|
1189
|
+
return "";
|
|
1190
|
+
}
|
|
1191
|
+
return col.title || "";
|
|
1192
|
+
}
|
|
1111
1193
|
function onColumnSort(col, click = true, options = {}) {
|
|
1112
1194
|
if (!(col == null ? void 0 : col.sorter))
|
|
1113
1195
|
return;
|
|
@@ -1214,7 +1296,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1214
1296
|
if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
|
|
1215
1297
|
const column = newOption.sortOption || tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
|
|
1216
1298
|
if (column)
|
|
1217
|
-
onColumnSort(column, false, { force: true, emit: !newOption.silent });
|
|
1299
|
+
onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
|
|
1218
1300
|
else
|
|
1219
1301
|
console.warn("Can not find column by dataIndex:", sortCol.value);
|
|
1220
1302
|
}
|
|
@@ -1329,7 +1411,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1329
1411
|
rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
|
|
1330
1412
|
colspan: col.colSpan,
|
|
1331
1413
|
style: normalizeStyle(getCellStyle(1, col, rowIndex)),
|
|
1332
|
-
title: col
|
|
1414
|
+
title: getHeaderTitle(col),
|
|
1333
1415
|
class: normalizeClass([
|
|
1334
1416
|
col.sorter ? "sortable" : "",
|
|
1335
1417
|
col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
|
|
@@ -1433,7 +1515,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1433
1515
|
key: 1,
|
|
1434
1516
|
class: "table-cell-wrapper",
|
|
1435
1517
|
title: row[col.dataIndex]
|
|
1436
|
-
}, toDisplayString(row[col.dataIndex] ??
|
|
1518
|
+
}, toDisplayString(row[col.dataIndex] ?? getEmptyCellText.value(col, row)), 9, _hoisted_14))
|
|
1437
1519
|
], 14, _hoisted_13);
|
|
1438
1520
|
}), 128))
|
|
1439
1521
|
], 46, _hoisted_11);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stk-table-vue",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Simple realtime virtual table for vue3&vue2.7",
|
|
5
5
|
"main": "./lib/stk-table-vue.js",
|
|
6
|
-
"types": "./lib/StkTable/index.d.ts",
|
|
6
|
+
"types": "./lib/src/StkTable/index.d.ts",
|
|
7
7
|
"packageManager": "pnpm@8.14.3",
|
|
8
8
|
"directories": {
|
|
9
9
|
"test": "test"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"postcss-preset-env": "^9.3.0",
|
|
50
50
|
"prettier": "^3.1.1",
|
|
51
51
|
"typescript": "^5.3.3",
|
|
52
|
-
"vite": "^5.
|
|
53
|
-
"vite-plugin-dts": "^3.
|
|
52
|
+
"vite": "^5.1.4",
|
|
53
|
+
"vite-plugin-dts": "^3.7.3",
|
|
54
54
|
"vitest": "^1.1.0",
|
|
55
|
-
"vue": "^3.
|
|
55
|
+
"vue": "^3.4.19",
|
|
56
56
|
"vue-eslint-parser": "^9.3.2"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|