stk-table-vue 0.2.2 → 0.2.5

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.
@@ -70,23 +70,35 @@ function useAutoResize({ tableContainer, initVirtualScroll, props, debounceMs })
70
70
  }, debounceMs);
71
71
  }
72
72
  }
73
- function insertToOrderedArray(sortState, newItem, targetArray) {
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, sortType);
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, type) {
109
- if (type === "number") {
110
- if (+a > +b)
111
- return 1;
112
- else if (+a === +b)
113
- return 0;
114
- else
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
- let isEmpty = row[sortField] === null || row[sortField] === "";
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 {
@@ -138,37 +151,32 @@ function separatedData(sortOption, targetDataSource, isNumber) {
138
151
  function tableSort(sortOption, order, dataSource, sortConfig = {}) {
139
152
  if (!(dataSource == null ? void 0 : dataSource.length))
140
153
  return dataSource || [];
141
- sortConfig = Object.assign({ emptyToBottom: false }, sortConfig);
154
+ sortConfig = { emptyToBottom: false, ...sortConfig };
142
155
  let targetDataSource = [...dataSource];
156
+ let sortField = sortOption.sortField || sortOption.dataIndex;
157
+ if (!order && sortConfig.defaultSort) {
158
+ order = sortConfig.defaultSort.order;
159
+ sortField = sortConfig.defaultSort.dataIndex;
160
+ }
143
161
  if (typeof sortOption.sorter === "function") {
144
162
  const customSorterData = sortOption.sorter(targetDataSource, { order, column: sortOption });
145
163
  if (customSorterData)
146
164
  targetDataSource = customSorterData;
147
165
  } else if (order) {
148
- const sortField = sortOption.sortField || sortOption.dataIndex;
149
166
  let { sortType } = sortOption;
150
167
  if (!sortType)
151
168
  sortType = typeof dataSource[0][sortField];
152
169
  const [valueArr, emptyArr] = separatedData(sortOption, targetDataSource, sortType === "number");
153
- if (sortType === "number") {
154
- if (order === "asc") {
155
- valueArr.sort((a, b) => +a[sortField] - +b[sortField]);
156
- targetDataSource = [...emptyArr, ...valueArr];
157
- } else {
158
- valueArr.sort((a, b) => +b[sortField] - +a[sortField]);
159
- targetDataSource = [...valueArr, ...emptyArr];
160
- }
170
+ const isNumber = sortType === "number";
171
+ if (order === "asc") {
172
+ valueArr.sort((a, b) => strCompare(a[sortField], b[sortField], isNumber, sortConfig.stringLocaleCompare));
161
173
  } else {
162
- if (order === "asc") {
163
- valueArr.sort((a, b) => String(a[sortField]).localeCompare(b[sortField]));
164
- targetDataSource = [...emptyArr, ...valueArr];
165
- } else {
166
- valueArr.sort((a, b) => String(a[sortField]).localeCompare(b[sortField]) * -1);
167
- targetDataSource = [...valueArr, ...emptyArr];
168
- }
174
+ valueArr.sort((a, b) => strCompare(b[sortField], a[sortField], isNumber, sortConfig.stringLocaleCompare));
169
175
  }
170
- if (sortConfig.emptyToBottom) {
176
+ if (order === "desc" || sortConfig.emptyToBottom) {
171
177
  targetDataSource = [...valueArr, ...emptyArr];
178
+ } else {
179
+ targetDataSource = [...emptyArr, ...valueArr];
172
180
  }
173
181
  }
174
182
  return targetDataSource;
@@ -184,10 +192,18 @@ function howDeepTheHeader(arr, level = 1) {
184
192
  return Math.max(...levels);
185
193
  }
186
194
  function getColWidth(col) {
187
- if (typeof (col == null ? void 0 : col.width) === "number") {
188
- return Math.floor(col.width ?? Default_Col_Width);
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";
189
205
  }
190
- return parseInt((col == null ? void 0 : col.width) ?? Default_Col_Width);
206
+ return val;
191
207
  }
192
208
  function useColResize({
193
209
  tableContainer,
@@ -367,36 +383,54 @@ function useFixedCol({ props, tableHeaderLast, tableContainer }) {
367
383
  updateFixedShadow
368
384
  };
369
385
  }
370
- function useFixedStyle({ props, tableHeaderLast, virtualScroll, virtualScrollX, virtualX_on, virtualX_offsetRight }) {
386
+ function useFixedStyle({
387
+ props,
388
+ tableHeaders,
389
+ virtualScroll,
390
+ virtualScrollX,
391
+ virtualX_on,
392
+ virtualX_offsetRight
393
+ }) {
371
394
  const fixedColumnsPositionStore = computed(() => {
372
- const store = {};
373
- const cols = [...tableHeaderLast.value];
374
- let left = 0;
375
- let rightStartIndex = 0;
376
- for (let i = 0; i < cols.length; i++) {
377
- const item = cols[i];
378
- if (item.fixed === "left") {
379
- store[item.dataIndex] = left;
380
- left += getColWidth(item);
381
- }
382
- if (!rightStartIndex && item.fixed === "right") {
383
- rightStartIndex = i;
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
+ }
384
413
  }
385
- }
386
- let right = 0;
387
- for (let i = cols.length - 1; i >= rightStartIndex; i--) {
388
- const item = cols[i];
389
- if (item.fixed === "right") {
390
- store[item.dataIndex] = right;
391
- right += getColWidth(item);
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
+ }
392
425
  }
393
- }
394
- return store;
426
+ });
427
+ return { refStore, colKeyStore };
395
428
  });
396
429
  function getFixedStyle(tagType, col, depth = 0) {
397
- const { fixed, dataIndex } = col;
430
+ const { fixed } = col;
398
431
  const isFixedLeft = fixed === "left";
399
432
  const style = {};
433
+ const { colKeyStore, refStore } = fixedColumnsPositionStore.value;
400
434
  if (Is_Legacy_Mode) {
401
435
  style.position = "relative";
402
436
  } else {
@@ -423,10 +457,11 @@ function useFixedStyle({ props, tableHeaderLast, virtualScroll, virtualScrollX,
423
457
  style.right = `${virtualX_offsetRight.value}px`;
424
458
  }
425
459
  } else {
460
+ const lr = (col.dataIndex ? colKeyStore[col.dataIndex] : refStore.get(col)) + "px";
426
461
  if (isFixedLeft) {
427
- style.left = fixedColumnsPositionStore.value[dataIndex] + "px";
462
+ style.left = lr;
428
463
  } else {
429
- style.right = fixedColumnsPositionStore.value[dataIndex] + "px";
464
+ style.right = lr;
430
465
  }
431
466
  }
432
467
  }
@@ -436,11 +471,14 @@ function useFixedStyle({ props, tableHeaderLast, virtualScroll, virtualScrollX,
436
471
  getFixedStyle
437
472
  };
438
473
  }
439
- function useHighlight({ props, tableContainer, rowKeyGen }) {
440
- const highlightInter = computed(() => {
441
- return interpolateRgb(Highlight_Color[props.theme].from, Highlight_Color[props.theme].to);
442
- });
443
- const highlightDimRows = /* @__PURE__ */ new Set();
474
+ const HIGHLIGHT_ROW_CLASS = "highlight-row";
475
+ const HIGHLIGHT_CELL_CLASS = "highlight-cell";
476
+ function useHighlight({ props, tableContainer }) {
477
+ const highlightRowStore = ref({});
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));
481
+ const highlightDimRowKeys = /* @__PURE__ */ new Set();
444
482
  const highlightDimRowsTimeout = /* @__PURE__ */ new Map();
445
483
  const highlightDimCellsTimeout = /* @__PURE__ */ new Map();
446
484
  let calcHighlightDimLoop = false;
@@ -451,18 +489,17 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
451
489
  const recursion = () => {
452
490
  window.setTimeout(() => {
453
491
  const nowTs = Date.now();
454
- const needDeleteRows = [];
455
- highlightDimRows.forEach((row) => {
456
- const progress = (nowTs - row._bgc_progress_ms) / Highlight_Duration;
492
+ highlightDimRowKeys.forEach((rowKeyValue) => {
493
+ const highlightItem = highlightRowStore.value[rowKeyValue];
494
+ const progress = (nowTs - highlightItem.bgc_progress_ms) / Highlight_Duration;
457
495
  if (0 < progress && progress < 1) {
458
- row._bgc = highlightInter.value(progress);
496
+ highlightItem.bgc = highlightInter.value(progress);
459
497
  } else {
460
- row._bgc = "";
461
- needDeleteRows.push(row);
498
+ highlightItem.bgc = "";
499
+ highlightDimRowKeys.delete(rowKeyValue);
462
500
  }
463
501
  });
464
- needDeleteRows.forEach((row) => highlightDimRows.delete(row));
465
- if (highlightDimRows.size > 0) {
502
+ if (highlightDimRowKeys.size > 0) {
466
503
  recursion();
467
504
  } else {
468
505
  calcHighlightDimLoop = false;
@@ -476,16 +513,16 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
476
513
  const cellEl = (_a = tableContainer.value) == null ? void 0 : _a.querySelector(`[data-row-key="${rowKeyValue}"]>[data-index="${dataIndex}"]`);
477
514
  if (!cellEl)
478
515
  return;
479
- if (cellEl.classList.contains("highlight-cell")) {
480
- cellEl.classList.remove("highlight-cell");
516
+ if (cellEl.classList.contains(HIGHLIGHT_CELL_CLASS)) {
517
+ cellEl.classList.remove(HIGHLIGHT_CELL_CLASS);
481
518
  void cellEl.offsetHeight;
482
519
  }
483
- cellEl.classList.add("highlight-cell");
520
+ cellEl.classList.add(HIGHLIGHT_CELL_CLASS);
484
521
  window.clearTimeout(highlightDimCellsTimeout.get(rowKeyValue));
485
522
  highlightDimCellsTimeout.set(
486
523
  rowKeyValue,
487
524
  window.setTimeout(() => {
488
- cellEl.classList.remove("highlight-cell");
525
+ cellEl.classList.remove(HIGHLIGHT_CELL_CLASS);
489
526
  highlightDimCellsTimeout.delete(rowKeyValue);
490
527
  }, Highlight_Duration)
491
528
  );
@@ -498,11 +535,12 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
498
535
  const nowTs = Date.now();
499
536
  for (let i = 0; i < rowKeyValues.length; i++) {
500
537
  const rowKeyValue = rowKeyValues[i];
501
- const row = props.dataSource.find((it) => rowKeyGen(it) === rowKeyValue);
502
- if (!row)
503
- continue;
504
- row._bgc_progress_ms = nowTs;
505
- highlightDimRows.add(row);
538
+ highlightRowStore.value[rowKeyValue] = {
539
+ bgc: "",
540
+ bgc_progress: 0,
541
+ bgc_progress_ms: nowTs
542
+ };
543
+ highlightDimRowKeys.add(rowKeyValue);
506
544
  }
507
545
  calcHighlightLoop();
508
546
  } else {
@@ -513,8 +551,8 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
513
551
  const rowEl = (_a = tableContainer.value) == null ? void 0 : _a.querySelector(`[data-row-key="${rowKeyValue}"]`);
514
552
  if (!rowEl)
515
553
  continue;
516
- if (rowEl.classList.contains("highlight-row")) {
517
- rowEl.classList.remove("highlight-row");
554
+ if (rowEl.classList.contains(HIGHLIGHT_ROW_CLASS)) {
555
+ rowEl.classList.remove(HIGHLIGHT_ROW_CLASS);
518
556
  needRepaint = true;
519
557
  }
520
558
  rowElTemp.push(rowEl);
@@ -522,7 +560,7 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
522
560
  highlightDimRowsTimeout.set(
523
561
  rowKeyValue,
524
562
  window.setTimeout(() => {
525
- rowEl.classList.remove("highlight-row");
563
+ rowEl.classList.remove(HIGHLIGHT_ROW_CLASS);
526
564
  highlightDimRowsTimeout.delete(rowKeyValue);
527
565
  }, Highlight_Duration)
528
566
  );
@@ -530,10 +568,11 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
530
568
  if (needRepaint) {
531
569
  void ((_b = tableContainer.value) == null ? void 0 : _b.offsetWidth);
532
570
  }
533
- rowElTemp.forEach((el) => el.classList.add("highlight-row"));
571
+ rowElTemp.forEach((el) => el.classList.add(HIGHLIGHT_ROW_CLASS));
534
572
  }
535
573
  }
536
574
  return {
575
+ highlightRowStore,
537
576
  setHighlightDimRow,
538
577
  setHighlightDimCell
539
578
  };
@@ -561,10 +600,11 @@ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll,
561
600
  if (!isMouseOver)
562
601
  return;
563
602
  e.preventDefault();
564
- const { scrollTop, rowHeight, pageSize } = virtualScroll.value;
603
+ const { scrollTop, rowHeight, containerHeight } = virtualScroll.value;
565
604
  const { scrollLeft } = virtualScrollX.value;
566
605
  const { headless, headerRowHeight } = props;
567
606
  const headerHeight = headless ? 0 : tableHeaders.value.length * (headerRowHeight || rowHeight);
607
+ const bodyPageSize = Math.floor((containerHeight - headerHeight) / rowHeight);
568
608
  if (e.code === SCROLL_CODES[0]) {
569
609
  scrollTo(scrollTop - rowHeight, null);
570
610
  } else if (e.code === SCROLL_CODES[1]) {
@@ -574,9 +614,9 @@ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll,
574
614
  } else if (e.code === SCROLL_CODES[3]) {
575
615
  scrollTo(null, scrollLeft - rowHeight);
576
616
  } else if (e.code === SCROLL_CODES[4]) {
577
- scrollTo(scrollTop - rowHeight * pageSize - headerHeight, null);
617
+ scrollTo(scrollTop - rowHeight * bodyPageSize + headerHeight, null);
578
618
  } else if (e.code === SCROLL_CODES[5]) {
579
- scrollTo(scrollTop + rowHeight * pageSize - headerHeight, null);
619
+ scrollTo(scrollTop + rowHeight * bodyPageSize - headerHeight, null);
580
620
  }
581
621
  }
582
622
  function handleMouseEnter() {
@@ -642,7 +682,13 @@ function useThDrag({ props, emits }) {
642
682
  };
643
683
  }
644
684
  const VUE2_SCROLL_TIMEOUT_MS = 200;
645
- function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLast }) {
685
+ function useVirtualScroll({
686
+ props,
687
+ tableContainer,
688
+ dataSourceCopy,
689
+ tableHeaderLast,
690
+ tableHeaders
691
+ }) {
646
692
  const virtualScroll = ref({
647
693
  containerHeight: 0,
648
694
  rowHeight: props.rowHeight,
@@ -720,11 +766,13 @@ function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLa
720
766
  } else {
721
767
  containerHeight = offsetHeight || Default_Table_Height;
722
768
  }
723
- Object.assign(virtualScroll.value, {
724
- containerHeight,
725
- pageSize: Math.ceil(containerHeight / rowHeight) + 1
726
- // 这里最终+1,因为headless=true无头时,需要上下各预渲染一行。
727
- });
769
+ const { headless, headerRowHeight } = props;
770
+ let pageSize = Math.ceil(containerHeight / rowHeight);
771
+ if (!headless) {
772
+ const headerToBodyRowHeightCount = Math.floor(tableHeaders.value.length * (headerRowHeight || rowHeight) / rowHeight);
773
+ pageSize -= headerToBodyRowHeightCount;
774
+ }
775
+ Object.assign(virtualScroll.value, { containerHeight, pageSize });
728
776
  updateVirtualScrollY(scrollTop);
729
777
  }
730
778
  function initVirtualScrollX() {
@@ -741,9 +789,27 @@ function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLa
741
789
  let vue2ScrollYTimeout = null;
742
790
  function updateVirtualScrollY(sTop = 0) {
743
791
  const { rowHeight, pageSize, scrollTop, startIndex: oldStartIndex } = virtualScroll.value;
744
- const startIndex = Math.floor(sTop / rowHeight);
745
- const offsetTop = startIndex * rowHeight;
792
+ virtualScroll.value.scrollTop = sTop;
793
+ let startIndex = Math.floor(sTop / rowHeight);
794
+ if (props.stripe) {
795
+ startIndex -= 1;
796
+ }
797
+ if (startIndex < 0) {
798
+ startIndex = 0;
799
+ }
800
+ if (props.stripe && startIndex !== 0) {
801
+ const scrollRows = Math.abs(oldStartIndex - startIndex);
802
+ if (scrollRows < 2) {
803
+ return;
804
+ } else if (scrollRows % 2) {
805
+ startIndex -= 1;
806
+ }
807
+ }
746
808
  let endIndex = startIndex + pageSize;
809
+ if (props.stripe) {
810
+ endIndex += 2;
811
+ }
812
+ const offsetTop = startIndex * rowHeight;
747
813
  if (endIndex > dataSourceCopy.value.length) {
748
814
  endIndex = dataSourceCopy.value.length;
749
815
  }
@@ -753,12 +819,11 @@ function useVirtualScroll({ props, tableContainer, dataSourceCopy, tableHeaderLa
753
819
  if (!props.optimizeVue2Scroll || sTop <= scrollTop || Math.abs(oldStartIndex - startIndex) >= pageSize) {
754
820
  Object.assign(virtualScroll.value, {
755
821
  startIndex,
756
- offsetTop,
757
822
  endIndex,
758
- scrollTop: sTop
823
+ offsetTop
759
824
  });
760
825
  } else {
761
- Object.assign(virtualScroll.value, { endIndex, scrollTop: sTop });
826
+ virtualScroll.value.endIndex = endIndex;
762
827
  vue2ScrollYTimeout = window.setTimeout(() => {
763
828
  Object.assign(virtualScroll.value, { startIndex, offsetTop });
764
829
  }, VUE2_SCROLL_TIMEOUT_MS);
@@ -887,8 +952,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
887
952
  virtualX: { type: Boolean, default: false },
888
953
  columns: { default: () => [] },
889
954
  dataSource: { default: () => [] },
890
- rowKey: { type: [String, Function], default: "" },
891
- colKey: { type: [String, Function], default: "dataIndex" },
955
+ rowKey: { type: [String, Number, Function], default: "" },
956
+ colKey: { type: [String, Number, Function], default: "dataIndex" },
892
957
  emptyCellText: { default: "--" },
893
958
  noDataFull: { type: Boolean, default: false },
894
959
  showNoData: { type: Boolean, default: true },
@@ -905,8 +970,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
905
970
  fixedColShadow: { type: Boolean, default: false },
906
971
  optimizeVue2Scroll: { type: Boolean, default: false },
907
972
  sortConfig: { default: () => ({
908
- emptyToBottom: false
909
- }) }
973
+ emptyToBottom: false,
974
+ stringLocaleCompare: true
975
+ }) },
976
+ hideHeaderTitle: { type: [Boolean, Array], default: false }
910
977
  },
911
978
  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"],
912
979
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -947,16 +1014,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
947
1014
  initVirtualScrollX,
948
1015
  updateVirtualScrollY,
949
1016
  updateVirtualScrollX
950
- } = useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast });
1017
+ } = useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast, tableHeaders });
951
1018
  const { getFixedStyle } = useFixedStyle({
952
1019
  props,
953
- tableHeaderLast,
1020
+ tableHeaders,
954
1021
  virtualScroll,
955
1022
  virtualScrollX,
956
1023
  virtualX_on,
957
1024
  virtualX_offsetRight
958
1025
  });
959
- const { setHighlightDimCell, setHighlightDimRow } = useHighlight({ props, tableContainer, rowKeyGen });
1026
+ const { highlightRowStore, setHighlightDimCell, setHighlightDimRow } = useHighlight({ props, tableContainer });
960
1027
  if (props.autoResize) {
961
1028
  useAutoResize({ tableContainer, initVirtualScroll, props, debounceMs: 200 });
962
1029
  }
@@ -1008,7 +1075,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1008
1075
  onMounted(() => {
1009
1076
  initVirtualScroll();
1010
1077
  updateFixedShadow();
1078
+ dealDefaultSorter();
1011
1079
  });
1080
+ function dealDefaultSorter() {
1081
+ if (!props.sortConfig.defaultSort)
1082
+ return;
1083
+ const { dataIndex, order } = props.sortConfig.defaultSort;
1084
+ setSorter(dataIndex, order);
1085
+ }
1012
1086
  function dealColumns() {
1013
1087
  tableHeaders.value = [];
1014
1088
  tableHeaderLast.value = [];
@@ -1023,17 +1097,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1023
1097
  tableHeaders.value[depth] = [];
1024
1098
  }
1025
1099
  let allChildrenLen = 0;
1100
+ let allChildrenWidthSum = 0;
1026
1101
  arr.forEach((col) => {
1027
1102
  col.__PARENT__ = parent;
1028
1103
  let colChildrenLen = 1;
1104
+ let colWidth = 0;
1029
1105
  if (col.children) {
1030
- colChildrenLen = flat(
1106
+ const [len, widthSum] = flat(
1031
1107
  col.children,
1032
1108
  col,
1033
1109
  depth + 1
1034
1110
  /* , col.fixed */
1035
1111
  );
1112
+ colChildrenLen = len;
1113
+ colWidth = widthSum;
1036
1114
  } else {
1115
+ colWidth = getColWidth(col);
1037
1116
  tempHeaderLast.push(col);
1038
1117
  }
1039
1118
  tableHeaders.value[depth].push(col);
@@ -1045,9 +1124,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1045
1124
  if (colSpan !== 1) {
1046
1125
  col.colSpan = colSpan;
1047
1126
  }
1127
+ if (!props.fixedMode && col.width === void 0) {
1128
+ col.width = colWidth + "px";
1129
+ }
1048
1130
  allChildrenLen += colChildrenLen;
1131
+ allChildrenWidthSum += colWidth;
1049
1132
  });
1050
- return allChildrenLen;
1133
+ return [allChildrenLen, allChildrenWidthSum];
1051
1134
  }
1052
1135
  flat(copyColumn, null);
1053
1136
  tableHeaderLast.value = tempHeaderLast;
@@ -1067,17 +1150,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1067
1150
  return typeof props.colKey === "function" ? props.colKey(col) : col[props.colKey];
1068
1151
  }
1069
1152
  function getColWidthStyle(col) {
1153
+ const width = getColWidthStr(col);
1154
+ const minWidth = getColWidthStr(col, "minWidth");
1155
+ const maxWidth = getColWidthStr(col, "maxWidth");
1070
1156
  const style = {
1071
- width: col.width,
1072
- minWidth: col.minWidth,
1073
- maxWidth: col.maxWidth
1157
+ width,
1158
+ minWidth: minWidth ?? width,
1159
+ maxWidth: maxWidth ?? width
1074
1160
  };
1075
1161
  if (props.colResizable) {
1076
- style.minWidth = col.width;
1077
- style.maxWidth = col.width;
1078
- } else {
1079
- style.minWidth = col.minWidth === void 0 ? col.width : col.minWidth;
1080
- style.maxWidth = col.maxWidth === void 0 ? col.width : col.maxWidth;
1162
+ style.minWidth = width;
1163
+ style.maxWidth = width;
1081
1164
  }
1082
1165
  return style;
1083
1166
  }
@@ -1093,6 +1176,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1093
1176
  }
1094
1177
  return style;
1095
1178
  }
1179
+ function getHeaderTitle(col) {
1180
+ if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(col.dataIndex)) {
1181
+ return "";
1182
+ }
1183
+ return col.title || "";
1184
+ }
1096
1185
  function onColumnSort(col, click = true, options = {}) {
1097
1186
  if (!(col == null ? void 0 : col.sorter))
1098
1187
  return;
@@ -1104,8 +1193,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1104
1193
  if (click)
1105
1194
  sortOrderIndex.value++;
1106
1195
  sortOrderIndex.value = sortOrderIndex.value % 3;
1107
- const order = sortSwitchOrder[sortOrderIndex.value];
1196
+ let order = sortSwitchOrder[sortOrderIndex.value];
1108
1197
  const sortConfig = props.sortConfig;
1198
+ const defaultSort = sortConfig.defaultSort;
1199
+ if (!order && defaultSort) {
1200
+ order = defaultSort.order;
1201
+ sortOrderIndex.value = sortSwitchOrder.indexOf(order);
1202
+ sortCol.value = defaultSort.dataIndex;
1203
+ }
1109
1204
  if (!props.sortRemote || options.force) {
1110
1205
  dataSourceCopy.value = tableSort(col, order, props.dataSource, sortConfig);
1111
1206
  }
@@ -1189,7 +1284,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1189
1284
  var _a;
1190
1285
  const newOption = { silent: true, sortOption: null, sort: true, ...option };
1191
1286
  sortCol.value = dataIndex;
1192
- sortOrderIndex.value = sortSwitchOrder.findIndex((it) => it === order);
1287
+ sortOrderIndex.value = sortSwitchOrder.indexOf(order);
1193
1288
  if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
1194
1289
  const column = newOption.sortOption || tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
1195
1290
  if (column)
@@ -1308,7 +1403,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1308
1403
  rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
1309
1404
  colspan: col.colSpan,
1310
1405
  style: normalizeStyle(getCellStyle(1, col, rowIndex)),
1311
- title: col.title,
1406
+ title: getHeaderTitle(col),
1312
1407
  class: normalizeClass([
1313
1408
  col.sorter ? "sortable" : "",
1314
1409
  col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
@@ -1377,6 +1472,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1377
1472
  }), 128)) : createCommentVNode("", true)
1378
1473
  ], 4)) : createCommentVNode("", true),
1379
1474
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, i) => {
1475
+ var _a;
1380
1476
  return openBlock(), createElementBlock("tr", {
1381
1477
  key: _ctx.rowKey ? rowKeyGen(row) : i,
1382
1478
  "data-row-key": _ctx.rowKey ? rowKeyGen(row) : i,
@@ -1386,7 +1482,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1386
1482
  [_ctx.rowClassName(row, i)]: true
1387
1483
  }),
1388
1484
  style: normalizeStyle({
1389
- backgroundColor: row._bgc
1485
+ backgroundColor: (_a = unref(highlightRowStore)[rowKeyGen(row)]) == null ? void 0 : _a.bgc
1390
1486
  }),
1391
1487
  onClick: (e) => onRowClick(e, row),
1392
1488
  onDblclick: (e) => onRowDblclick(e, row),