stk-table-vue 0.6.2 → 0.6.4

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 CHANGED
@@ -180,7 +180,7 @@ export type StkProps = {
180
180
  dataSource?: any[];
181
181
  /** 行唯一键 (行唯一值不能为undefined)*/
182
182
  rowKey?: UniqKeyProp;
183
- /** 列唯一键 */
183
+ /** 列唯一键。默认`dataIndex`*/
184
184
  colKey?: UniqKeyProp;
185
185
  /** 空值展示文字 */
186
186
  emptyCellText?: string | ((option: { row: DT; col: StkTableColumn<DT> }) => string);
@@ -1,4 +1,4 @@
1
- import { AutoRowHeightConfig, DragRowConfig, ExpandConfig, HeaderDragConfig, HighlightConfig, Order, PrivateRowDT, SeqConfig, SortConfig, SortOption, SortState, StkTableColumn, UniqKeyProp } from './types/index';
1
+ import { AutoRowHeightConfig, DragRowConfig, ExpandConfig, HeaderDragConfig, HighlightConfig, Order, PrivateRowDT, SeqConfig, SortConfig, SortOption, StkTableColumn, UniqKeyProp } from './types/index';
2
2
  /** Generic stands for DataType */
3
3
  type DT = any & PrivateRowDT;
4
4
  /**
@@ -19,15 +19,15 @@ declare function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option?: {
19
19
  silent: boolean;
20
20
  }): void;
21
21
  /**
22
- * 设置表头排序状态
23
- * @param dataIndex 列字段
22
+ * 设置表头排序状态。
23
+ * @param colKey 列唯一键字段。如果你想要取消排序状态,请使用`resetSorter`
24
24
  * @param order 正序倒序
25
25
  * @param option.sortOption 指定排序参数。同 StkTableColumn 中排序相关字段。建议从columns中find得到。
26
26
  * @param option.sort 是否触发排序-默认true
27
27
  * @param option.silent 是否禁止触发回调-默认true
28
28
  * @param option.force 是否触发排序-默认true
29
29
  */
30
- declare function setSorter(dataIndex: string, order: Order, option?: {
30
+ declare function setSorter(colKey: string, order: Order, option?: {
31
31
  sortOption?: SortOption<DT>;
32
32
  force?: boolean;
33
33
  silent?: boolean;
@@ -43,7 +43,10 @@ declare function scrollTo(top?: number | null, left?: number | null): void;
43
43
  /** get current table data */
44
44
  declare function getTableData(): any[];
45
45
  /** get current sort info */
46
- declare function getSortColumns(): Partial<SortState<DT>>[];
46
+ declare function getSortColumns(): {
47
+ key: string | number | symbol | undefined;
48
+ order: "desc" | "asc";
49
+ }[];
47
50
  /**
48
51
  *
49
52
  * @param rowKeyOrRow rowKey or row
@@ -158,7 +161,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
158
161
  optimizeVue2Scroll?: boolean | undefined;
159
162
  /** 排序配置 */
160
163
  sortConfig?: SortConfig<any> | undefined;
161
- /** 隐藏头部title。可传入dataIndex数组 */
164
+ /** 隐藏头部title。可传入colKey数组 */
162
165
  hideHeaderTitle?: boolean | string[] | undefined;
163
166
  /** 高亮配置 */
164
167
  highlightConfig?: HighlightConfig | undefined;
@@ -226,7 +229,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
226
229
  * en: Set highlight cell
227
230
  * @see {@link setHighlightDimCell}
228
231
  */
229
- setHighlightDimCell: (rowKeyValue: import('./types/index').UniqKey, dataIndex: string, option?: import('./types/highlightDimOptions').HighlightDimCellOption) => void;
232
+ setHighlightDimCell: (rowKeyValue: import('./types/index').UniqKey, colKeyValue: string, option?: import('./types/highlightDimOptions').HighlightDimCellOption) => void;
230
233
  /**
231
234
  * 设置高亮行
232
235
  *
@@ -235,9 +238,9 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
235
238
  */
236
239
  setHighlightDimRow: (rowKeyValues: import('./types/index').UniqKey[], option?: import('./types/highlightDimOptions').HighlightDimRowOption) => void;
237
240
  /**
238
- * 表格排序列dataIndex
241
+ * 表格排序列colKey
239
242
  *
240
- * en: Table sort column dataIndex
243
+ * en: Table sort column colKey
241
244
  */
242
245
  sortCol: import('vue').Ref<string | number | symbol | undefined, string | number | symbol | undefined>;
243
246
  /**
@@ -403,7 +406,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
403
406
  optimizeVue2Scroll?: boolean | undefined;
404
407
  /** 排序配置 */
405
408
  sortConfig?: SortConfig<any> | undefined;
406
- /** 隐藏头部title。可传入dataIndex数组 */
409
+ /** 隐藏头部title。可传入colKey数组 */
407
410
  hideHeaderTitle?: boolean | string[] | undefined;
408
411
  /** 高亮配置 */
409
412
  highlightConfig?: HighlightConfig | undefined;
@@ -435,6 +438,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
435
438
  width: string;
436
439
  minWidth: string;
437
440
  maxWidth: string;
441
+ sortConfig: SortConfig<any>;
438
442
  rowHeight: number;
439
443
  headerRowHeight: number | null;
440
444
  headless: boolean;
@@ -472,7 +476,6 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
472
476
  bordered: boolean | "h" | "v" | "body-v";
473
477
  autoResize: boolean | (() => void);
474
478
  fixedColShadow: boolean;
475
- sortConfig: SortConfig<any>;
476
479
  hideHeaderTitle: boolean | string[];
477
480
  highlightConfig: HighlightConfig;
478
481
  seqConfig: SeqConfig;
@@ -38,7 +38,6 @@ export type CustomCell<T extends CustomCellProps<U> | CustomHeaderCellProps<U>,
38
38
  export type StkTableColumn<T extends Record<string, any>> = {
39
39
  /**
40
40
  * 用于区分相同dataIndex 的列。
41
- * 需要自行配置colKey="(col: StkTableColumn<any>) => col.key ?? col.dataIndex"
42
41
  */
43
42
  key?: any;
44
43
  /**
@@ -72,6 +71,8 @@ export type StkTableColumn<T extends Record<string, any>> = {
72
71
  sortField?: keyof T;
73
72
  /** 排序方式。按数字/字符串 */
74
73
  sortType?: 'number' | 'string';
74
+ /** 配置当前列的排序规则 */
75
+ sortConfig?: Pick<SortConfig<T>, 'emptyToBottom' | 'stringLocaleCompare'>;
75
76
  /** 固定列 */
76
77
  fixed?: 'left' | 'right' | null;
77
78
  /** private */ rowSpan?: number;
@@ -144,6 +145,12 @@ export type SortConfig<T extends Record<string, any>> = {
144
145
  * 类似onMounted时,调用setSorter点了下表头。
145
146
  */
146
147
  defaultSort?: {
148
+ /**
149
+ * 列唯一键,
150
+ *
151
+ * 如果您配了 `props.colKey` 则这里表示的列唯一键的值
152
+ */
153
+ key?: StkTableColumn<T>['key'];
147
154
  dataIndex: StkTableColumn<T>['dataIndex'];
148
155
  order: Order;
149
156
  sortField?: StkTableColumn<T>['sortField'];
@@ -2,12 +2,12 @@ import { ComputedRef, ShallowRef } from 'vue';
2
2
  import { StkTableColumn, UniqKey } from './types';
3
3
  type Params<T extends Record<string, any>> = {
4
4
  colKeyGen: ComputedRef<(col: StkTableColumn<T>) => UniqKey>;
5
- tableHeaders: ShallowRef<StkTableColumn<T>[][]>;
5
+ tableHeadersForCalc: ShallowRef<StkTableColumn<T>[][]>;
6
6
  };
7
7
  /**
8
8
  * 固定列fixed左侧或者右侧的距离
9
9
  * - col.fixed = left 则得到距离左侧的距离
10
10
  * - col.fixed = right 则得到距离右侧的距离
11
11
  */
12
- export declare function useGetFixedColPosition<DT extends Record<string, any>>({ tableHeaders, colKeyGen }: Params<DT>): ComputedRef<(col: StkTableColumn<any>) => number>;
12
+ export declare function useGetFixedColPosition<DT extends Record<string, any>>({ tableHeadersForCalc, colKeyGen }: Params<DT>): ComputedRef<(col: StkTableColumn<any>) => number>;
13
13
  export {};
@@ -12,6 +12,6 @@ type Params = {
12
12
  export declare function useHighlight({ props, stkTableId, tableContainerRef }: Params): {
13
13
  highlightSteps: number | null;
14
14
  setHighlightDimRow: (rowKeyValues: UniqKey[], option?: HighlightDimRowOption) => void;
15
- setHighlightDimCell: (rowKeyValue: UniqKey, dataIndex: string, option?: HighlightDimCellOption) => void;
15
+ setHighlightDimCell: (rowKeyValue: UniqKey, colKeyValue: string, option?: HighlightDimCellOption) => void;
16
16
  };
17
17
  export {};
@@ -14,6 +14,6 @@ export declare function useThDrag<DT extends Record<string, any>>({ props, emits
14
14
  onThDragOver: (e: DragEvent) => void;
15
15
  onThDrop: (e: DragEvent) => void;
16
16
  /** 是否可拖拽 */
17
- isHeaderDraggable: (col: StkTableColumn<DT>) => boolean;
17
+ isHeaderDraggable: (col: StkTableColumn<DT>) => any;
18
18
  };
19
19
  export {};
@@ -4,7 +4,7 @@ import { Order, SortConfig, SortOption, SortState, StkTableColumn } from '../typ
4
4
  *
5
5
  * 注意:不会改变原数组,返回新数组
6
6
  * @param sortState
7
- * @param sortState.dataIndex 排序的列
7
+ * @param sortState.dataIndex 排序的字段
8
8
  * @param sortState.order 排序顺序
9
9
  * @param sortState.sortType 排序方式
10
10
  * @param newItem 要插入的数据
@@ -34,8 +34,8 @@ export declare function strCompare(a: string, b: string, isNumber: boolean, loca
34
34
  * @param dataSource 排序的数组
35
35
  */
36
36
  export declare function tableSort<T extends Record<string, any>>(sortOption: SortOption<T>, order: Order, dataSource: T[], sortConfig?: SortConfig<T>): T[];
37
- /** 表头column配置的层级 */
37
+ /** 多级表头深度 从0开始为一级*/
38
38
  export declare function howDeepTheHeader(arr: StkTableColumn<any>[], level?: number): number;
39
- /** number列宽+px */
40
- export declare function transformWidthToStr(width?: string | number): string | undefined;
39
+ /** number width +px */
40
+ export declare function transformWidthToStr(width?: string | number): string;
41
41
  export declare function getBrowsersVersion(browserName: string): number;
@@ -147,7 +147,7 @@ function tableSort(sortOption, order, dataSource, sortConfig = {}) {
147
147
  }
148
148
  return targetDataSource;
149
149
  }
150
- function howDeepTheHeader(arr, level = 1) {
150
+ function howDeepTheHeader(arr, level = 0) {
151
151
  const levels = [level];
152
152
  arr.forEach((item) => {
153
153
  var _a;
@@ -158,10 +158,8 @@ function howDeepTheHeader(arr, level = 1) {
158
158
  return Math.max(...levels);
159
159
  }
160
160
  function transformWidthToStr(width) {
161
- if (typeof width === "number") {
162
- return width + "px";
163
- }
164
- return width;
161
+ const numberWidth = Number(width);
162
+ return width + (!Number.isNaN(numberWidth) ? "px" : "");
165
163
  }
166
164
  function getBrowsersVersion(browserName) {
167
165
  try {
@@ -369,7 +367,8 @@ function useColResize({
369
367
  const { clientX } = e;
370
368
  let moveX = clientX - startX;
371
369
  const currentColWidth = getCalculatedColWidth(lastCol);
372
- if (currentColWidth + moveX < props.colMinWidth) {
370
+ const minWidth = (lastCol == null ? void 0 : lastCol.minWidth) ?? props.colMinWidth;
371
+ if (currentColWidth + moveX < minWidth) {
373
372
  moveX = -currentColWidth;
374
373
  }
375
374
  const offsetTableX = startOffsetTableX + moveX;
@@ -529,7 +528,8 @@ function useFixedStyle({
529
528
  if (isRelativeMode.value) {
530
529
  style.top = virtualScroll.value.scrollTop + "px";
531
530
  } else {
532
- style.top = depth * props.rowHeight + "px";
531
+ const rowHeight = props.headerRowHeight ?? props.rowHeight;
532
+ style.top = depth * rowHeight + "px";
533
533
  }
534
534
  }
535
535
  const { scrollLeft, scrollWidth, offsetLeft, containerWidth } = virtualScrollX.value;
@@ -554,17 +554,17 @@ function useFixedStyle({
554
554
  }
555
555
  return getFixedStyle;
556
556
  }
557
- function useGetFixedColPosition({ tableHeaders, colKeyGen }) {
557
+ function useGetFixedColPosition({ tableHeadersForCalc, colKeyGen }) {
558
558
  const getFixedColPosition = computed(() => {
559
559
  const colKeyStore = {};
560
560
  const refStore = /* @__PURE__ */ new WeakMap();
561
- tableHeaders.value.forEach((cols) => {
561
+ tableHeadersForCalc.value.forEach((cols) => {
562
562
  let left = 0;
563
563
  let rightStartIndex = 0;
564
564
  for (let i = 0; i < cols.length; i++) {
565
565
  const item = cols[i];
566
566
  if (item.fixed === "left") {
567
- const colKey = colKeyGen.value(item) || item.dataIndex;
567
+ const colKey = colKeyGen.value(item);
568
568
  if (colKey) {
569
569
  colKeyStore[colKey] = left;
570
570
  } else {
@@ -579,7 +579,7 @@ function useGetFixedColPosition({ tableHeaders, colKeyGen }) {
579
579
  let right = 0;
580
580
  for (let i = cols.length - 1; i >= rightStartIndex; i--) {
581
581
  const item = cols[i];
582
- const colKey = colKeyGen.value(item) || item.dataIndex;
582
+ const colKey = colKeyGen.value(item);
583
583
  if (item.fixed === "right") {
584
584
  if (colKey) {
585
585
  colKeyStore[colKey] = right;
@@ -591,7 +591,7 @@ function useGetFixedColPosition({ tableHeaders, colKeyGen }) {
591
591
  }
592
592
  });
593
593
  return (col) => {
594
- const colKey = colKeyGen.value(col) || col.dataIndex;
594
+ const colKey = colKeyGen.value(col);
595
595
  return colKey ? colKeyStore[colKey] : refStore.get(col) || 0;
596
596
  };
597
597
  });
@@ -675,9 +675,9 @@ function useHighlight({ props, stkTableId, tableContainerRef }) {
675
675
  };
676
676
  recursion();
677
677
  }
678
- function setHighlightDimCell(rowKeyValue, dataIndex, option = {}) {
678
+ function setHighlightDimCell(rowKeyValue, colKeyValue, option = {}) {
679
679
  var _a;
680
- const cellEl = (_a = tableContainerRef.value) == null ? void 0 : _a.querySelector(`[data-row-key="${rowKeyValue}"]>[data-index="${dataIndex}"]`);
680
+ const cellEl = (_a = tableContainerRef.value) == null ? void 0 : _a.querySelector(`[data-cell-key="${rowKeyValue}--${colKeyValue}"]`);
681
681
  const { className, method, duration, keyframe } = {
682
682
  className: HIGHLIGHT_CELL_CLASS,
683
683
  method: "animation",
@@ -939,7 +939,7 @@ function useThDrag({ props, emits, colKeyGen }) {
939
939
  onThDragOver,
940
940
  onThDrop,
941
941
  /** 是否可拖拽 */
942
- isHeaderDraggable: (col) => !dragConfig.value.disabled(col)
942
+ isHeaderDraggable: (col) => dragConfig.value.draggable && !dragConfig.value.disabled(col)
943
943
  };
944
944
  }
945
945
  const TR_DRAGGING_CLASS = "tr-dragging";
@@ -1334,7 +1334,7 @@ const _hoisted_9 = {
1334
1334
  };
1335
1335
  const _hoisted_10 = ["colspan"];
1336
1336
  const _hoisted_11 = { class: "table-cell-wrapper" };
1337
- const _hoisted_12 = ["data-index", "cell-key", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1337
+ const _hoisted_12 = ["data-cell-key", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1338
1338
  const _hoisted_13 = ["title"];
1339
1339
  const _hoisted_14 = { key: 1 };
1340
1340
  const _sfc_main = /* @__PURE__ */ defineComponent({
@@ -1409,6 +1409,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1409
1409
  const sortSwitchOrder = [null, "desc", "asc"];
1410
1410
  const tableHeaders = shallowRef([]);
1411
1411
  const tableHeaderLast = shallowRef([]);
1412
+ const tableHeadersForCalc = shallowRef([]);
1412
1413
  const dataSourceCopy = shallowRef([...props.dataSource]);
1413
1414
  const colKeyGen = computed(() => {
1414
1415
  if (typeof props.colKey === "function") {
@@ -1444,7 +1445,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1444
1445
  setAutoHeight,
1445
1446
  clearAllAutoHeight
1446
1447
  } = useVirtualScroll({ tableContainerRef, trRef, props, dataSourceCopy, tableHeaderLast, tableHeaders, rowKeyGen });
1447
- const getFixedColPosition = useGetFixedColPosition({ colKeyGen, tableHeaders });
1448
+ const getFixedColPosition = useGetFixedColPosition({ colKeyGen, tableHeadersForCalc });
1448
1449
  const getFixedStyle = useFixedStyle({
1449
1450
  props,
1450
1451
  isRelativeMode,
@@ -1527,7 +1528,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1527
1528
  nextTick(() => initVirtualScrollY());
1528
1529
  }
1529
1530
  if (sortCol.value) {
1530
- const column = tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
1531
+ const column = tableHeaderLast.value.find((it) => colKeyGen.value(it) === sortCol.value);
1531
1532
  onColumnSort(column, false);
1532
1533
  }
1533
1534
  },
@@ -1547,11 +1548,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1547
1548
  });
1548
1549
  function dealDefaultSorter() {
1549
1550
  if (!props.sortConfig.defaultSort) return;
1550
- const { dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
1551
- setSorter(dataIndex, order, { force: false, silent });
1551
+ const { key, dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
1552
+ setSorter(key || dataIndex, order, { force: false, silent });
1552
1553
  }
1553
1554
  function dealColumns() {
1554
- let tableHeadersTemp = [];
1555
+ const tableHeadersTemp = [];
1556
+ const tableHeadersForCalcTemp = [];
1555
1557
  let copyColumn = props.columns;
1556
1558
  if (isRelativeMode.value) {
1557
1559
  let leftCol = [];
@@ -1568,15 +1570,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1568
1570
  });
1569
1571
  copyColumn = [...leftCol, ...centerCol, ...rightCol];
1570
1572
  }
1571
- const deep = howDeepTheHeader(copyColumn);
1573
+ const maxDeep = howDeepTheHeader(copyColumn);
1572
1574
  const tempHeaderLast = [];
1573
- if (deep > 1 && props.virtualX) {
1575
+ if (maxDeep > 0 && props.virtualX) {
1574
1576
  console.error("多级表头不支持横向虚拟滚动");
1575
1577
  }
1578
+ for (let i = 0; i <= maxDeep; i++) {
1579
+ tableHeadersTemp[i] = [];
1580
+ tableHeadersForCalcTemp[i] = [];
1581
+ }
1576
1582
  function flat(arr, parent, depth = 0) {
1577
- if (!tableHeadersTemp[depth]) {
1578
- tableHeadersTemp[depth] = [];
1579
- }
1580
1583
  let allChildrenLen = 0;
1581
1584
  let allChildrenWidthSum = 0;
1582
1585
  arr.forEach((col) => {
@@ -1592,20 +1595,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1592
1595
  );
1593
1596
  colChildrenLen = len;
1594
1597
  colWidth = widthSum;
1598
+ tableHeadersForCalcTemp[depth].push(col);
1595
1599
  } else {
1596
1600
  colWidth = getColWidth(col);
1597
1601
  tempHeaderLast.push(col);
1602
+ for (let i = depth; i <= maxDeep; i++) {
1603
+ tableHeadersForCalcTemp[i].push(col);
1604
+ }
1598
1605
  }
1606
+ col.__WIDTH__ = colWidth;
1599
1607
  tableHeadersTemp[depth].push(col);
1600
- const rowSpan = col.children ? 1 : deep - depth;
1608
+ const rowSpan = col.children ? 1 : maxDeep - depth + 1;
1601
1609
  const colSpan = colChildrenLen;
1602
- if (rowSpan !== 1) {
1610
+ if (rowSpan > 1) {
1603
1611
  col.rowSpan = rowSpan;
1604
1612
  }
1605
- if (colSpan !== 1) {
1613
+ if (colSpan > 1) {
1606
1614
  col.colSpan = colSpan;
1607
1615
  }
1608
- col.__WIDTH__ = colWidth;
1609
1616
  allChildrenLen += colChildrenLen;
1610
1617
  allChildrenWidthSum += colWidth;
1611
1618
  });
@@ -1614,6 +1621,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1614
1621
  flat(copyColumn, null);
1615
1622
  tableHeaders.value = tableHeadersTemp;
1616
1623
  tableHeaderLast.value = tempHeaderLast;
1624
+ tableHeadersForCalc.value = tableHeadersForCalcTemp;
1617
1625
  }
1618
1626
  function rowKeyGen(row) {
1619
1627
  if (!row) return row;
@@ -1669,34 +1677,48 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1669
1677
  };
1670
1678
  });
1671
1679
  function getHeaderTitle(col) {
1672
- if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(col.dataIndex)) {
1680
+ const colKey = colKeyGen.value(col);
1681
+ if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(colKey)) {
1673
1682
  return "";
1674
1683
  }
1675
1684
  return col.title || "";
1676
1685
  }
1677
1686
  function onColumnSort(col, click = true, options = {}) {
1678
- if (!(col == null ? void 0 : col.sorter) && click) {
1687
+ if (!col) {
1688
+ console.warn("onColumnSort: col is not found");
1689
+ return;
1690
+ }
1691
+ if (!col.sorter && click) {
1679
1692
  return;
1680
1693
  }
1681
1694
  options = { force: false, emit: false, ...options };
1682
- if (sortCol.value !== col.dataIndex) {
1683
- sortCol.value = col.dataIndex;
1695
+ const colKey = colKeyGen.value(col);
1696
+ if (sortCol.value !== colKey) {
1697
+ sortCol.value = colKey;
1684
1698
  sortOrderIndex.value = 0;
1685
1699
  }
1686
1700
  if (click) sortOrderIndex.value++;
1687
1701
  sortOrderIndex.value = sortOrderIndex.value % 3;
1688
1702
  let order = sortSwitchOrder[sortOrderIndex.value];
1689
- const sortConfig = props.sortConfig;
1703
+ const sortConfig = { ...props.sortConfig, ...col.sortConfig };
1690
1704
  const defaultSort = sortConfig.defaultSort;
1691
1705
  if (!order && defaultSort) {
1692
- if (!defaultSort.dataIndex) {
1693
- console.error("sortConfig.defaultSort.dataIndex is required");
1706
+ const colKey2 = defaultSort.key || defaultSort.dataIndex;
1707
+ if (!colKey2) {
1708
+ console.error("sortConfig.defaultSort key or dataIndex is required");
1694
1709
  return;
1695
1710
  }
1696
1711
  order = defaultSort.order || "desc";
1697
1712
  sortOrderIndex.value = sortSwitchOrder.indexOf(order);
1698
- sortCol.value = defaultSort.dataIndex;
1699
- col = props.columns.find((item) => item.dataIndex === defaultSort.dataIndex) || null;
1713
+ sortCol.value = colKey2;
1714
+ col = null;
1715
+ for (const row of tableHeaders.value) {
1716
+ const c = row.find((item) => colKeyGen.value(item) === colKey2);
1717
+ if (c) {
1718
+ col = c;
1719
+ break;
1720
+ }
1721
+ }
1700
1722
  }
1701
1723
  if (!props.sortRemote || options.force) {
1702
1724
  const sortOption = col || defaultSort;
@@ -1859,15 +1881,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1859
1881
  );
1860
1882
  }
1861
1883
  }
1862
- function setSorter(dataIndex, order, option = {}) {
1884
+ function setSorter(colKey, order, option = {}) {
1863
1885
  var _a;
1864
1886
  const newOption = { silent: true, sortOption: null, sort: true, ...option };
1865
- sortCol.value = dataIndex;
1887
+ sortCol.value = colKey;
1866
1888
  sortOrderIndex.value = sortSwitchOrder.indexOf(order);
1867
1889
  if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
1868
- const column = newOption.sortOption || tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
1890
+ const column = newOption.sortOption || tableHeaderLast.value.find((it) => colKeyGen.value(it) === sortCol.value);
1869
1891
  if (column) onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
1870
- else console.warn("Can not find column by dataIndex:", sortCol.value);
1892
+ else console.warn("Can not find column by key:", sortCol.value);
1871
1893
  }
1872
1894
  return dataSourceCopy.value;
1873
1895
  }
@@ -1887,7 +1909,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1887
1909
  function getSortColumns() {
1888
1910
  const sortOrder = sortSwitchOrder[sortOrderIndex.value];
1889
1911
  if (!sortOrder) return [];
1890
- return [{ dataIndex: sortCol.value, order: sortOrder }];
1912
+ return [{ key: sortCol.value, order: sortOrder }];
1891
1913
  }
1892
1914
  function toggleExpandRow(row, col) {
1893
1915
  const isExpand = (row == null ? void 0 : row.__EXPANDED__) === col ? !(row == null ? void 0 : row.__EXPANDED__) : true;
@@ -1985,9 +2007,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1985
2007
  */
1986
2008
  setHighlightDimRow,
1987
2009
  /**
1988
- * 表格排序列dataIndex
2010
+ * 表格排序列colKey
1989
2011
  *
1990
- * en: Table sort column dataIndex
2012
+ * en: Table sort column colKey
1991
2013
  */
1992
2014
  sortCol,
1993
2015
  /**
@@ -2111,7 +2133,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2111
2133
  }, null, 4)) : createCommentVNode("", true),
2112
2134
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
2113
2135
  return openBlock(), createElementBlock("th", {
2114
- key: col.dataIndex,
2136
+ key: colKeyGen.value(col),
2115
2137
  "data-col-key": colKeyGen.value(col),
2116
2138
  draggable: unref(isHeaderDraggable)(col) ? "true" : "false",
2117
2139
  rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
@@ -2120,7 +2142,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2120
2142
  title: getHeaderTitle(col),
2121
2143
  class: normalizeClass([
2122
2144
  col.sorter ? "sortable" : "",
2123
- col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
2145
+ colKeyGen.value(col) === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
2124
2146
  col.headerClassName,
2125
2147
  unref(fixedColClassMap).get(colKeyGen.value(col))
2126
2148
  ]),
@@ -2191,7 +2213,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2191
2213
  unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_7)) : createCommentVNode("", true),
2192
2214
  _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
2193
2215
  return openBlock(), createElementBlock("td", {
2194
- key: col.dataIndex,
2216
+ key: colKeyGen.value(col),
2195
2217
  style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col)))
2196
2218
  }, null, 4);
2197
2219
  }), 128)) : createCommentVNode("", true)
@@ -2199,16 +2221,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2199
2221
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, rowIndex) => {
2200
2222
  var _a, _b;
2201
2223
  return openBlock(), createElementBlock("tr", {
2202
- id: unref(stkTableId) + "-" + (_ctx.rowKey ? rowKeyGen(row) : unref(virtualScroll).startIndex + rowIndex),
2224
+ id: unref(stkTableId) + "-" + (_ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex),
2203
2225
  ref_for: true,
2204
2226
  ref_key: "trRef",
2205
2227
  ref: trRef,
2206
- key: _ctx.rowKey ? rowKeyGen(row) : unref(virtualScroll).startIndex + rowIndex,
2207
- "data-row-key": _ctx.rowKey ? rowKeyGen(row) : unref(virtualScroll).startIndex + rowIndex,
2228
+ key: _ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
2229
+ "data-row-key": _ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
2208
2230
  class: normalizeClass({
2209
2231
  active: _ctx.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
2210
2232
  hover: props.showTrHoverClass && (_ctx.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
2211
- [_ctx.rowClassName(row, unref(virtualScroll).startIndex + rowIndex)]: true,
2233
+ [_ctx.rowClassName(row, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)]: true,
2212
2234
  expanded: row == null ? void 0 : row.__EXPANDED__,
2213
2235
  "expanded-row": row && row.__EXPANDED_ROW__
2214
2236
  }),
@@ -2219,7 +2241,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2219
2241
  onDblclick: (e) => onRowDblclick(e, row),
2220
2242
  onContextmenu: (e) => onRowMenu(e, row),
2221
2243
  onMouseover: (e) => onTrMouseOver(e, row),
2222
- onDrop: (e) => unref(onTrDrop)(e, unref(virtualScroll).startIndex + rowIndex)
2244
+ onDrop: (e) => unref(onTrDrop)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
2223
2245
  }, [
2224
2246
  unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_9)) : createCommentVNode("", true),
2225
2247
  row && row.__EXPANDED_ROW__ ? (openBlock(), createElementBlock("td", {
@@ -2239,9 +2261,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2239
2261
  ])
2240
2262
  ], 8, _hoisted_10)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(virtualX_columnPart), (col, colIndex) => {
2241
2263
  return openBlock(), createElementBlock("td", {
2242
- key: col.dataIndex,
2243
- "data-index": col.dataIndex,
2244
- "cell-key": rowKeyGen(row) + "--" + colKeyGen.value(col),
2264
+ key: colKeyGen.value(col),
2265
+ "data-cell-key": cellKeyGen(row, col),
2245
2266
  style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col))),
2246
2267
  class: normalizeClass([
2247
2268
  col.className,
@@ -2267,7 +2288,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2267
2288
  class: "table-cell-wrapper",
2268
2289
  col,
2269
2290
  row,
2270
- rowIndex: unref(virtualScroll).startIndex + rowIndex,
2291
+ rowIndex: (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
2271
2292
  colIndex,
2272
2293
  cellValue: row == null ? void 0 : row[col.dataIndex],
2273
2294
  expanded: (row == null ? void 0 : row.__EXPANDED__) || null
@@ -2277,10 +2298,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2277
2298
  title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : ""
2278
2299
  }, [
2279
2300
  col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2280
- createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + unref(virtualScroll).startIndex + rowIndex + 1), 1)
2301
+ createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex + 1), 1)
2281
2302
  ], 64)) : col.type === "expand" ? (openBlock(), createElementBlock("span", _hoisted_14, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2282
2303
  createVNode(DragHandle, {
2283
- onDragstart: (e) => unref(onTrDragStart)(e, unref(virtualScroll).startIndex + rowIndex)
2304
+ onDragstart: (e) => unref(onTrDragStart)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
2284
2305
  }, null, 8, ["onDragstart"]),
2285
2306
  createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
2286
2307
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
package/lib/style.css CHANGED
@@ -38,8 +38,6 @@
38
38
  display:flex;
39
39
  flex-direction:column;
40
40
  box-sizing:border-box;
41
- border-left:1px solid #e8e8f4;
42
- border-left:1px solid var(--border-color);
43
41
  background-image:linear-gradient(180deg, #e8e8f4 1px, transparent 1px), linear-gradient(270deg, #e8e8f4 1px, transparent 1px), linear-gradient(0deg, #e8e8f4 1px, transparent 1px);
44
42
  background-image:var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
45
43
  }
@@ -78,12 +76,8 @@
78
76
  .stk-table.is-col-resizing th{
79
77
  pointer-events:none;
80
78
  }
81
- .stk-table.border-h{
82
- --bg-border-right:linear-gradient(transparent, transparent);
83
- --bg-border-left:linear-gradient(transparent, transparent);
84
- }
85
- .stk-table.border-v{
86
- --bg-border-bottom:linear-gradient(transparent, transparent);
79
+ .stk-table.border{
80
+ border-left:1px solid var(--border-color);
87
81
  }
88
82
  .stk-table.border th,
89
83
  .stk-table.border td{
@@ -92,6 +86,15 @@
92
86
  .stk-table.border thead tr:first-child th{
93
87
  background-image:var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
94
88
  }
89
+ .stk-table.border-h{
90
+ border-left:none;
91
+ --bg-border-right:linear-gradient(transparent, transparent);
92
+ --bg-border-left:linear-gradient(transparent, transparent);
93
+ }
94
+ .stk-table.border-v{
95
+ --bg-border-bottom:linear-gradient(transparent, transparent);
96
+ --bg-border-top:linear-gradient(transparent, transparent);
97
+ }
95
98
  .stk-table.border-body-v tbody{
96
99
  --bg-border-bottom:linear-gradient(transparent, transparent);
97
100
  }