stk-table-vue 0.4.13 → 0.4.14

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
@@ -139,7 +139,7 @@ export type StkProps = {
139
139
  rowHover?: boolean;
140
140
  /** 是否高亮选中的行 */
141
141
  rowActive?: boolean;
142
- /** 当前行再次点击否可以取消 */
142
+ /** 当前行再次点击否可以取消 (rowActive=true)*/
143
143
  rowCurrentRevokable?: boolean;
144
144
  /** 表头行高。default = rowHeight */
145
145
  headerRowHeight?: number | null;
@@ -169,9 +169,12 @@ export type StkProps = {
169
169
  showOverflow?: boolean;
170
170
  /** 是否增加行hover class */
171
171
  showTrHoverClass?: boolean;
172
-
173
172
  /** 是否高亮鼠标悬浮的单元格 */
174
173
  cellHover?: boolean;
174
+ /** 是否高亮选中的单元格 */
175
+ cellActive?: boolean;
176
+ /** 单元格再次点击否可以取消选中 (cellActive=true)*/
177
+ selectedCellRevokable?: boolean;
175
178
  /** 表头是否可拖动。支持回调函数。 */
176
179
  headerDrag?: boolean | ((col: StkTableColumn<DT>) => boolean);
177
180
  /**
@@ -272,6 +275,11 @@ export type StkProps = {
272
275
  * ```(ev: MouseEvent | null, row: DT | undefined,, data: { select: boolean })```
273
276
  */
274
277
  (e: 'current-change', ev: MouseEvent | null, row: DT | undefined,, data: { select: boolean }): void;
278
+ /**
279
+ * 选中单元格触发。ev返回null表示不是点击事件触发的
280
+ * ```(ev: MouseEvent | null, data: { select: boolean; row: DT | undefined; col: StkTableColumn<DT> | null })```
281
+ */
282
+ (e: 'cell-selected', ev: MouseEvent | null, data: { select: boolean; row: DT | undefined; col: StkTableColumn<DT> | null }): void;
275
283
  /**
276
284
  * 行双击事件
277
285
  * ```(ev: MouseEvent, row: DT)```
@@ -357,6 +365,8 @@ defineExpose({
357
365
  initVirtualScrollY,
358
366
  /** 设置当前选中行 */
359
367
  setCurrentRow,
368
+ /** 设置当前选中单元格 (props.cellActive=true)*/
369
+ setSelectedCell,
360
370
  /** 设置高亮渐暗单元格 */
361
371
  setHighlightDimCell,
362
372
  /** 设置高亮渐暗行 */
@@ -602,6 +612,9 @@ export type SortConfig<T extends Record<string, any>> = {
602
612
  ### props.autoResize
603
613
  * 手动设置为 `props.autoResize=false`。可取消监听的性能消耗。适用于宽度高度不变的表格。
604
614
 
615
+ ### props.smoothScroll
616
+ * 高版本浏览器滚动默认有惯性。会频繁触发 `onscroll` 回调。因此 chrome > 85 默认关闭,使用 `onwheel` 代理滚动,且可防止滚动白屏。
617
+
605
618
  ## Tips
606
619
  ### props.fixedMode
607
620
  * **低版本浏览器** 需要设置 `props.width`(default: width=fit-content不生效)。否则列宽不设宽度会变为0。
@@ -3,13 +3,22 @@ import { HighlightConfig, Order, SeqConfig, SortConfig, SortOption, SortState, S
3
3
  /** Generic stands for DataType */
4
4
  type DT = any;
5
5
  /**
6
- * 选中一行,
6
+ * 选中一行
7
7
  * @param {string} rowKeyOrRow selected rowKey, undefined to unselect
8
8
  * @param {boolean} option.silent if emit current-change. default:false(not emit `current-change`)
9
9
  */
10
10
  declare function setCurrentRow(rowKeyOrRow: string | undefined | DT, option?: {
11
11
  silent: boolean;
12
12
  }): void;
13
+ /**
14
+ * set highlight active cell (props.cellActive=true)
15
+ * @param row row if undefined, clear highlight
16
+ * @param col column
17
+ * @param option.silent if emit current-change. default:false(not emit `current-change`)
18
+ */
19
+ declare function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option?: {
20
+ silent: boolean;
21
+ }): void;
13
22
  /**
14
23
  * 设置表头排序状态
15
24
  * @param dataIndex 列字段
@@ -57,7 +66,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
57
66
  rowHover?: boolean | undefined;
58
67
  /** 是否高亮选中的行 */
59
68
  rowActive?: boolean | undefined;
60
- /** 当前行再次点击否可以取消 */
69
+ /** 当前行再次点击否可以取消 (rowActive=true)*/
61
70
  rowCurrentRevokable?: boolean | undefined;
62
71
  /** 表头行高。default = rowHeight */
63
72
  headerRowHeight?: number | null | undefined;
@@ -92,6 +101,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
92
101
  showTrHoverClass?: boolean | undefined;
93
102
  /** 是否高亮鼠标悬浮的单元格 */
94
103
  cellHover?: boolean | undefined;
104
+ /** 是否高亮选中的单元格 */
105
+ cellActive?: boolean | undefined;
106
+ /** 单元格再次点击否可以取消选中 (cellActive=true)*/
107
+ selectedCellRevokable?: boolean | undefined;
95
108
  /** 表头是否可拖动。支持回调函数。 */
96
109
  headerDrag?: boolean | ((col: StkTableColumn<any>) => boolean) | undefined;
97
110
  /**
@@ -176,6 +189,8 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
176
189
  showOverflow: boolean;
177
190
  showTrHoverClass: boolean;
178
191
  cellHover: boolean;
192
+ cellActive: boolean;
193
+ selectedCellRevokable: boolean;
179
194
  headerDrag: boolean;
180
195
  rowClassName: () => "";
181
196
  colResizable: boolean;
@@ -194,22 +209,24 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
194
209
  cellFixedMode: string;
195
210
  smoothScroll: boolean;
196
211
  }>, {
197
- /** 初始化横向纵向虚拟滚动 */
212
+ /** @see {@link initVirtualScroll} */
198
213
  initVirtualScroll: (height?: number | undefined) => void;
199
- /** 初始化横向虚拟滚动 */
214
+ /** @see {@link initVirtualScrollX} */
200
215
  initVirtualScrollX: () => void;
201
- /** 初始化纵向虚拟滚动 */
216
+ /** @see {@link initVirtualScrollY} */
202
217
  initVirtualScrollY: (height?: number | undefined) => void;
203
- /** 设置当前选中行 */
218
+ /** @see {@link setCurrentRow} */
204
219
  setCurrentRow: typeof setCurrentRow;
205
- /** 设置高亮渐暗单元格 */
220
+ /** @see {@link setSelectedCell} */
221
+ setSelectedCell: typeof setSelectedCell;
222
+ /** @see {@link setHighlightDimCell} */
206
223
  setHighlightDimCell: (rowKeyValue: import('./types/index').UniqKey, dataIndex: string, option?: {
207
224
  className?: string | undefined;
208
225
  method?: "animation" | "css" | undefined;
209
226
  keyframe?: Keyframe[] | PropertyIndexedKeyframes | null | undefined;
210
227
  duration?: number | undefined;
211
228
  }) => void;
212
- /** 设置高亮渐暗行 */
229
+ /** @see {@link setHighlightDimRow} */
213
230
  setHighlightDimRow: (rowKeyValues: import('./types/index').UniqKey[], option?: {
214
231
  method?: "animation" | "css" | "js" | undefined;
215
232
  useCss?: boolean | undefined;
@@ -219,15 +236,15 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
219
236
  }) => void;
220
237
  /** 表格排序列dataIndex */
221
238
  sortCol: import('vue').Ref<string | number | symbol | undefined>;
222
- /** 获取当前排序状态 */
239
+ /** @see {@link getSortColumns} */
223
240
  getSortColumns: typeof getSortColumns;
224
- /** 设置排序 */
241
+ /** @see {@link setSorter} */
225
242
  setSorter: typeof setSorter;
226
- /** 重置排序 */
243
+ /** @see {@link resetSorter} */
227
244
  resetSorter: typeof resetSorter;
228
- /** 滚动至 */
245
+ /** @see {@link scrollTo} */
229
246
  scrollTo: typeof scrollTo;
230
- /** 获取表格数据 */
247
+ /** @see {@link getTableData} */
231
248
  getTableData: typeof getTableData;
232
249
  }, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
233
250
  "sort-change": (col: StkTableColumn<any> | null, order: Order, data: any[], sortConfig: SortConfig<any>) => void;
@@ -235,6 +252,11 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
235
252
  "current-change": (ev: MouseEvent | null, row: any, data: {
236
253
  select: boolean;
237
254
  }) => void;
255
+ "cell-selected": (ev: MouseEvent | null, data: {
256
+ select: boolean;
257
+ row: any;
258
+ col: StkTableColumn<any> | undefined;
259
+ }) => void;
238
260
  "row-dblclick": (ev: MouseEvent, row: any) => void;
239
261
  "header-row-menu": (ev: MouseEvent) => void;
240
262
  "row-menu": (ev: MouseEvent, row: any) => void;
@@ -251,6 +273,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
251
273
  "col-order-change": (dragStartKey: string, targetColKey: string) => void;
252
274
  "th-drag-start": (dragStartKey: string) => void;
253
275
  "th-drop": (targetColKey: string) => void;
276
+ "col-resize": (cols: StkTableColumn<any>) => void;
254
277
  "update:columns": (cols: StkTableColumn<any>[]) => void;
255
278
  }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
256
279
  width?: string | undefined;
@@ -272,7 +295,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
272
295
  rowHover?: boolean | undefined;
273
296
  /** 是否高亮选中的行 */
274
297
  rowActive?: boolean | undefined;
275
- /** 当前行再次点击否可以取消 */
298
+ /** 当前行再次点击否可以取消 (rowActive=true)*/
276
299
  rowCurrentRevokable?: boolean | undefined;
277
300
  /** 表头行高。default = rowHeight */
278
301
  headerRowHeight?: number | null | undefined;
@@ -307,6 +330,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
307
330
  showTrHoverClass?: boolean | undefined;
308
331
  /** 是否高亮鼠标悬浮的单元格 */
309
332
  cellHover?: boolean | undefined;
333
+ /** 是否高亮选中的单元格 */
334
+ cellActive?: boolean | undefined;
335
+ /** 单元格再次点击否可以取消选中 (cellActive=true)*/
336
+ selectedCellRevokable?: boolean | undefined;
310
337
  /** 表头是否可拖动。支持回调函数。 */
311
338
  headerDrag?: boolean | ((col: StkTableColumn<any>) => boolean) | undefined;
312
339
  /**
@@ -391,6 +418,8 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
391
418
  showOverflow: boolean;
392
419
  showTrHoverClass: boolean;
393
420
  cellHover: boolean;
421
+ cellActive: boolean;
422
+ selectedCellRevokable: boolean;
394
423
  headerDrag: boolean;
395
424
  rowClassName: () => "";
396
425
  colResizable: boolean;
@@ -414,6 +443,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
414
443
  endIndex: number;
415
444
  }) => any) | undefined;
416
445
  "onUpdate:columns"?: ((cols: StkTableColumn<any>[]) => any) | undefined;
446
+ "onCol-resize"?: ((cols: StkTableColumn<any>) => any) | undefined;
417
447
  "onTh-drag-start"?: ((dragStartKey: string) => any) | undefined;
418
448
  "onCol-order-change"?: ((dragStartKey: string, targetColKey: string) => any) | undefined;
419
449
  "onTh-drop"?: ((targetColKey: string) => any) | undefined;
@@ -422,6 +452,11 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
422
452
  "onCurrent-change"?: ((ev: MouseEvent | null, row: any, data: {
423
453
  select: boolean;
424
454
  }) => any) | undefined;
455
+ "onCell-selected"?: ((ev: MouseEvent | null, data: {
456
+ select: boolean;
457
+ row: any;
458
+ col: StkTableColumn<any> | undefined;
459
+ }) => any) | undefined;
425
460
  "onRow-dblclick"?: ((ev: MouseEvent, row: any) => any) | undefined;
426
461
  "onHeader-row-menu"?: ((ev: MouseEvent) => any) | undefined;
427
462
  "onRow-menu"?: ((ev: MouseEvent, row: any) => any) | undefined;
@@ -461,6 +496,8 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<__
461
496
  showOverflow: boolean;
462
497
  showTrHoverClass: boolean;
463
498
  cellHover: boolean;
499
+ cellActive: boolean;
500
+ selectedCellRevokable: boolean;
464
501
  headerDrag: boolean | ((col: StkTableColumn<any>) => boolean);
465
502
  rowClassName: (row: any, i: number) => string;
466
503
  colResizable: boolean;
@@ -362,6 +362,7 @@ function useColResize({
362
362
  return;
363
363
  curCol.width = width + "px";
364
364
  emits("update:columns", [...props.columns]);
365
+ emits("col-resize", { ...curCol });
365
366
  if (colResizeIndicatorRef.value) {
366
367
  const style = colResizeIndicatorRef.value.style;
367
368
  style.display = "none";
@@ -1177,7 +1178,7 @@ const _hoisted_12 = {
1177
1178
  key: 0,
1178
1179
  class: "vt-x-left"
1179
1180
  };
1180
- const _hoisted_13 = ["data-index", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1181
+ const _hoisted_13 = ["data-index", "cell-key", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1181
1182
  const _hoisted_14 = ["title"];
1182
1183
  const _sfc_main = /* @__PURE__ */ defineComponent({
1183
1184
  __name: "StkTable",
@@ -1208,6 +1209,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1208
1209
  showOverflow: { type: Boolean, default: false },
1209
1210
  showTrHoverClass: { type: Boolean, default: false },
1210
1211
  cellHover: { type: Boolean, default: false },
1212
+ cellActive: { type: Boolean, default: false },
1213
+ selectedCellRevokable: { type: Boolean, default: true },
1211
1214
  headerDrag: { type: [Boolean, Function], default: false },
1212
1215
  rowClassName: { type: Function, default: () => "" },
1213
1216
  colResizable: { type: Boolean, default: false },
@@ -1226,7 +1229,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1226
1229
  cellFixedMode: { default: "sticky" },
1227
1230
  smoothScroll: { type: Boolean, default: DEFAULT_SMOOTH_SCROLL }
1228
1231
  },
1229
- emits: ["sort-change", "row-click", "current-change", "row-dblclick", "header-row-menu", "row-menu", "cell-click", "cell-mouseenter", "cell-mouseleave", "cell-mouseover", "header-cell-click", "scroll", "scroll-x", "col-order-change", "th-drag-start", "th-drop", "update:columns"],
1232
+ emits: ["sort-change", "row-click", "current-change", "cell-selected", "row-dblclick", "header-row-menu", "row-menu", "cell-click", "cell-mouseenter", "cell-mouseleave", "cell-mouseover", "header-cell-click", "scroll", "scroll-x", "col-order-change", "th-drag-start", "th-drop", "col-resize", "update:columns"],
1230
1233
  setup(__props, { expose: __expose, emit: __emit }) {
1231
1234
  const stkTableId = createStkTableId();
1232
1235
  const props = __props;
@@ -1236,7 +1239,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1236
1239
  const colResizeIndicatorRef = ref();
1237
1240
  const isRelativeMode = ref(IS_LEGACY_MODE ? true : props.cellFixedMode === "relative");
1238
1241
  const currentRow = shallowRef();
1239
- const currentRowKey = ref(null);
1242
+ const currentRowKey = ref(void 0);
1243
+ const currentSelectedCellKey = ref(void 0);
1240
1244
  let currentHoverRow = null;
1241
1245
  const currentHoverRowKey = ref(null);
1242
1246
  let sortCol = ref();
@@ -1461,6 +1465,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1461
1465
  }
1462
1466
  return key;
1463
1467
  }
1468
+ function cellKeyGen(row, col) {
1469
+ return rowKeyGen(row) + "--" + colKeyGen.value(col);
1470
+ }
1464
1471
  const cellStyleMap = computed(() => {
1465
1472
  const thMap = /* @__PURE__ */ new Map();
1466
1473
  const tdMap = /* @__PURE__ */ new Map();
@@ -1561,6 +1568,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1561
1568
  emits("row-menu", e, row);
1562
1569
  }
1563
1570
  function onCellClick(e, row, col) {
1571
+ if (props.rowActive) {
1572
+ const cellKey = cellKeyGen(row, col);
1573
+ if (props.selectedCellRevokable && currentSelectedCellKey.value === cellKey) {
1574
+ currentSelectedCellKey.value = void 0;
1575
+ emits("cell-selected", e, { select: false, row, col });
1576
+ } else {
1577
+ currentSelectedCellKey.value = cellKey;
1578
+ emits("cell-selected", e, { select: true, row, col });
1579
+ }
1580
+ }
1564
1581
  emits("cell-click", e, row, col);
1565
1582
  }
1566
1583
  function onHeaderCellClick(e, col) {
@@ -1641,7 +1658,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1641
1658
  function setCurrentRow(rowKeyOrRow, option = { silent: false }) {
1642
1659
  if (!dataSourceCopy.value.length)
1643
1660
  return;
1644
- if (rowKeyOrRow === void 0) {
1661
+ const select = rowKeyOrRow !== void 0;
1662
+ if (!select) {
1645
1663
  currentRow.value = void 0;
1646
1664
  currentRowKey.value = void 0;
1647
1665
  } else if (typeof rowKeyOrRow === "string") {
@@ -1662,7 +1680,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1662
1680
  /** no Event */
1663
1681
  null,
1664
1682
  currentRow.value,
1665
- { select: true }
1683
+ { select }
1684
+ );
1685
+ }
1686
+ }
1687
+ function setSelectedCell(row, col, option = { silent: false }) {
1688
+ if (!dataSourceCopy.value.length)
1689
+ return;
1690
+ const select = row !== void 0 && col !== void 0;
1691
+ currentSelectedCellKey.value = select ? cellKeyGen(row, col) : void 0;
1692
+ if (!option.silent) {
1693
+ emits(
1694
+ "cell-selected",
1695
+ /** no Event */
1696
+ null,
1697
+ { row, col, select }
1666
1698
  );
1667
1699
  }
1668
1700
  }
@@ -1703,29 +1735,31 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1703
1735
  return [{ dataIndex: sortCol.value, order: sortOrder }];
1704
1736
  }
1705
1737
  __expose({
1706
- /** 初始化横向纵向虚拟滚动 */
1738
+ /** @see {@link initVirtualScroll} */
1707
1739
  initVirtualScroll,
1708
- /** 初始化横向虚拟滚动 */
1740
+ /** @see {@link initVirtualScrollX} */
1709
1741
  initVirtualScrollX,
1710
- /** 初始化纵向虚拟滚动 */
1742
+ /** @see {@link initVirtualScrollY} */
1711
1743
  initVirtualScrollY,
1712
- /** 设置当前选中行 */
1744
+ /** @see {@link setCurrentRow} */
1713
1745
  setCurrentRow,
1714
- /** 设置高亮渐暗单元格 */
1746
+ /** @see {@link setSelectedCell} */
1747
+ setSelectedCell,
1748
+ /** @see {@link setHighlightDimCell} */
1715
1749
  setHighlightDimCell,
1716
- /** 设置高亮渐暗行 */
1750
+ /** @see {@link setHighlightDimRow} */
1717
1751
  setHighlightDimRow,
1718
1752
  /** 表格排序列dataIndex */
1719
1753
  sortCol,
1720
- /** 获取当前排序状态 */
1754
+ /** @see {@link getSortColumns} */
1721
1755
  getSortColumns,
1722
- /** 设置排序 */
1756
+ /** @see {@link setSorter} */
1723
1757
  setSorter,
1724
- /** 重置排序 */
1758
+ /** @see {@link resetSorter} */
1725
1759
  resetSorter,
1726
- /** 滚动至 */
1760
+ /** @see {@link scrollTo} */
1727
1761
  scrollTo,
1728
- /** 获取表格数据 */
1762
+ /** @see {@link getTableData} */
1729
1763
  getTableData
1730
1764
  });
1731
1765
  return (_ctx, _cache) => {
@@ -1746,6 +1780,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1746
1780
  "border-body-v": props.bordered === "body-v",
1747
1781
  stripe: props.stripe,
1748
1782
  "cell-hover": props.cellHover,
1783
+ "cell-active": props.cellActive,
1749
1784
  "row-hover": props.rowHover,
1750
1785
  "row-active": props.rowActive,
1751
1786
  "text-overflow": props.showOverflow,
@@ -1885,8 +1920,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1885
1920
  return openBlock(), createElementBlock("td", {
1886
1921
  key: col.dataIndex,
1887
1922
  "data-index": col.dataIndex,
1923
+ "cell-key": rowKeyGen(row) + "--" + colKeyGen.value(col),
1888
1924
  style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col))),
1889
- class: normalizeClass([col.className, unref(fixedColClassMap).get(colKeyGen.value(col)), col.type === "seq" ? "seq-column" : ""]),
1925
+ class: normalizeClass([
1926
+ col.className,
1927
+ unref(fixedColClassMap).get(colKeyGen.value(col)),
1928
+ {
1929
+ "seq-column": col.type === "seq",
1930
+ active: currentSelectedCellKey.value === cellKeyGen(row, col)
1931
+ }
1932
+ ]),
1890
1933
  onClick: (e) => onCellClick(e, row, col),
1891
1934
  onMouseenter: (e) => onCellMouseEnter(e, row, col),
1892
1935
  onMouseleave: (e) => onCellMouseLeave(e, row, col),
package/lib/style.css CHANGED
@@ -12,6 +12,7 @@
12
12
  --border-width:1px;
13
13
  --td-bgc:#fff;
14
14
  --td-hover-color:#71a2fd;
15
+ --td-active-color:#386ccc;
15
16
  --th-bgc:#fafafc;
16
17
  --th-color:#272841;
17
18
  --tr-active-bgc:#e6f7ff;
@@ -46,6 +47,7 @@
46
47
  --th-color:#C0C0D1;
47
48
  --td-bgc:#1b1b24;
48
49
  --td-hover-color:#70a6ff;
50
+ --td-active-color:#386ccc;
49
51
  --border-color:#292933;
50
52
  --tr-active-bgc:#283f63;
51
53
  --tr-hover-bgc:#1a2b46;
@@ -112,6 +114,9 @@
112
114
  .stk-table.cell-hover tbody td:hover{
113
115
  box-shadow:inset 0 0 0 2px var(--td-hover-color);
114
116
  }
117
+ .stk-table.cell-active tbody td.active{
118
+ box-shadow:inset 0 0 0 2px var(--td-active-color);
119
+ }
115
120
  .stk-table.text-overflow .table-cell-wrapper{
116
121
  white-space:nowrap;
117
122
  overflow:hidden;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "description": "Simple realtime virtual table for vue3 and vue2.7",
5
5
  "main": "./lib/stk-table-vue.js",
6
6
  "types": "./lib/src/StkTable/index.d.ts",
@@ -17,6 +17,7 @@
17
17
  'border-body-v': props.bordered === 'body-v',
18
18
  stripe: props.stripe,
19
19
  'cell-hover': props.cellHover,
20
+ 'cell-active': props.cellActive,
20
21
  'row-hover': props.rowHover,
21
22
  'row-active': props.rowActive,
22
23
  'text-overflow': props.showOverflow,
@@ -151,8 +152,16 @@
151
152
  v-for="(col, colIndex) in virtualX_columnPart"
152
153
  :key="col.dataIndex"
153
154
  :data-index="col.dataIndex"
155
+ :cell-key="rowKeyGen(row) + '--' + colKeyGen(col)"
154
156
  :style="cellStyleMap[TagType.TD].get(colKeyGen(col))"
155
- :class="[col.className, fixedColClassMap.get(colKeyGen(col)), col.type === 'seq' ? 'seq-column' : '']"
157
+ :class="[
158
+ col.className,
159
+ fixedColClassMap.get(colKeyGen(col)),
160
+ {
161
+ 'seq-column': col.type === 'seq',
162
+ active: currentSelectedCellKey === cellKeyGen(row, col),
163
+ },
164
+ ]"
156
165
  @click="e => onCellClick(e, row, col)"
157
166
  @mouseenter="e => onCellMouseEnter(e, row, col)"
158
167
  @mouseleave="e => onCellMouseLeave(e, row, col)"
@@ -234,7 +243,7 @@ const props = withDefaults(
234
243
  rowHover?: boolean;
235
244
  /** 是否高亮选中的行 */
236
245
  rowActive?: boolean;
237
- /** 当前行再次点击否可以取消 */
246
+ /** 当前行再次点击否可以取消 (rowActive=true)*/
238
247
  rowCurrentRevokable?: boolean;
239
248
  /** 表头行高。default = rowHeight */
240
249
  headerRowHeight?: number | null;
@@ -266,6 +275,10 @@ const props = withDefaults(
266
275
  showTrHoverClass?: boolean;
267
276
  /** 是否高亮鼠标悬浮的单元格 */
268
277
  cellHover?: boolean;
278
+ /** 是否高亮选中的单元格 */
279
+ cellActive?: boolean;
280
+ /** 单元格再次点击否可以取消选中 (cellActive=true)*/
281
+ selectedCellRevokable?: boolean;
269
282
  /** 表头是否可拖动。支持回调函数。 */
270
283
  headerDrag?: boolean | ((col: StkTableColumn<DT>) => boolean);
271
284
  /**
@@ -351,6 +364,8 @@ const props = withDefaults(
351
364
  showOverflow: false,
352
365
  showTrHoverClass: false,
353
366
  cellHover: false,
367
+ cellActive: false,
368
+ selectedCellRevokable: true,
354
369
  headerDrag: false,
355
370
  rowClassName: () => '',
356
371
  colResizable: false,
@@ -387,6 +402,11 @@ const emits = defineEmits<{
387
402
  * ```(ev: MouseEvent | null, row: DT | undefined, data: { select: boolean })```
388
403
  */
389
404
  (e: 'current-change', ev: MouseEvent | null, row: DT | undefined, data: { select: boolean }): void;
405
+ /**
406
+ * 选中单元格触发。ev返回null表示不是点击事件触发的
407
+ * ```(ev: MouseEvent | null, data: { select: boolean; row: DT | undefined; col: StkTableColumn<DT> | null })```
408
+ */
409
+ (e: 'cell-selected', ev: MouseEvent | null, data: { select: boolean; row: DT | undefined; col: StkTableColumn<DT> | undefined }): void;
390
410
  /**
391
411
  * 行双击事件
392
412
  * ```(ev: MouseEvent, row: DT)```
@@ -484,7 +504,9 @@ const currentRow = shallowRef<DT>();
484
504
  * 保存当前选中行的key<br>
485
505
  * 原因:vue3 不用ref包dataSource时,row为原始对象,与currentItem(Ref)相比会不相等。
486
506
  */
487
- const currentRowKey = ref<any>(null);
507
+ const currentRowKey = ref<any>(void 0);
508
+ /** 当前选中的单元格key */
509
+ const currentSelectedCellKey = ref<any>(void 0);
488
510
  /** 当前hover行 */
489
511
  let currentHoverRow: DT | null = null;
490
512
  /** 当前hover的行的key */
@@ -799,6 +821,11 @@ function rowKeyGen(row: DT | null | undefined) {
799
821
  return key;
800
822
  }
801
823
 
824
+ /** 单元格唯一值 */
825
+ function cellKeyGen(row: DT | null | undefined, col: StkTableColumn<DT>) {
826
+ return rowKeyGen(row) + '--' + colKeyGen.value(col);
827
+ }
828
+
802
829
  /** 单元格样式 */
803
830
  const cellStyleMap = computed(() => {
804
831
  const thMap = new Map();
@@ -925,6 +952,16 @@ function onRowMenu(e: MouseEvent, row: DT) {
925
952
 
926
953
  /** 单元格单击 */
927
954
  function onCellClick(e: MouseEvent, row: DT, col: StkTableColumn<DT>) {
955
+ if (props.rowActive) {
956
+ const cellKey = cellKeyGen(row, col);
957
+ if (props.selectedCellRevokable && currentSelectedCellKey.value === cellKey) {
958
+ currentSelectedCellKey.value = void 0;
959
+ emits('cell-selected', e, { select: false, row, col });
960
+ } else {
961
+ currentSelectedCellKey.value = cellKey;
962
+ emits('cell-selected', e, { select: true, row, col });
963
+ }
964
+ }
928
965
  emits('cell-click', e, row, col);
929
966
  }
930
967
 
@@ -1040,13 +1077,14 @@ function onTrMouseOver(_e: MouseEvent, row: DT) {
1040
1077
  }
1041
1078
 
1042
1079
  /**
1043
- * 选中一行,
1080
+ * 选中一行
1044
1081
  * @param {string} rowKeyOrRow selected rowKey, undefined to unselect
1045
1082
  * @param {boolean} option.silent if emit current-change. default:false(not emit `current-change`)
1046
1083
  */
1047
1084
  function setCurrentRow(rowKeyOrRow: string | undefined | DT, option = { silent: false }) {
1048
1085
  if (!dataSourceCopy.value.length) return;
1049
- if (rowKeyOrRow === void 0) {
1086
+ const select = rowKeyOrRow !== void 0;
1087
+ if (!select) {
1050
1088
  currentRow.value = void 0;
1051
1089
  currentRowKey.value = void 0;
1052
1090
  } else if (typeof rowKeyOrRow === 'string') {
@@ -1062,7 +1100,22 @@ function setCurrentRow(rowKeyOrRow: string | undefined | DT, option = { silent:
1062
1100
  currentRowKey.value = rowKeyGen(rowKeyOrRow);
1063
1101
  }
1064
1102
  if (!option.silent) {
1065
- emits('current-change', /** no Event */ null, currentRow.value, { select: true });
1103
+ emits('current-change', /** no Event */ null, currentRow.value, { select });
1104
+ }
1105
+ }
1106
+
1107
+ /**
1108
+ * set highlight active cell (props.cellActive=true)
1109
+ * @param row row if undefined, clear highlight
1110
+ * @param col column
1111
+ * @param option.silent if emit current-change. default:false(not emit `current-change`)
1112
+ */
1113
+ function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option = { silent: false }) {
1114
+ if (!dataSourceCopy.value.length) return;
1115
+ const select = row !== void 0 && col !== void 0;
1116
+ currentSelectedCellKey.value = select ? cellKeyGen(row, col) : void 0;
1117
+ if (!option.silent) {
1118
+ emits('cell-selected', /** no Event */ null, { row, col, select });
1066
1119
  }
1067
1120
  }
1068
1121
 
@@ -1120,29 +1173,31 @@ function getSortColumns(): Partial<SortState<DT>>[] {
1120
1173
  }
1121
1174
 
1122
1175
  defineExpose({
1123
- /** 初始化横向纵向虚拟滚动 */
1176
+ /** @see {@link initVirtualScroll} */
1124
1177
  initVirtualScroll,
1125
- /** 初始化横向虚拟滚动 */
1178
+ /** @see {@link initVirtualScrollX} */
1126
1179
  initVirtualScrollX,
1127
- /** 初始化纵向虚拟滚动 */
1180
+ /** @see {@link initVirtualScrollY} */
1128
1181
  initVirtualScrollY,
1129
- /** 设置当前选中行 */
1182
+ /** @see {@link setCurrentRow} */
1130
1183
  setCurrentRow,
1131
- /** 设置高亮渐暗单元格 */
1184
+ /** @see {@link setSelectedCell} */
1185
+ setSelectedCell,
1186
+ /** @see {@link setHighlightDimCell} */
1132
1187
  setHighlightDimCell,
1133
- /** 设置高亮渐暗行 */
1188
+ /** @see {@link setHighlightDimRow} */
1134
1189
  setHighlightDimRow,
1135
1190
  /** 表格排序列dataIndex */
1136
1191
  sortCol,
1137
- /** 获取当前排序状态 */
1192
+ /** @see {@link getSortColumns} */
1138
1193
  getSortColumns,
1139
- /** 设置排序 */
1194
+ /** @see {@link setSorter} */
1140
1195
  setSorter,
1141
- /** 重置排序 */
1196
+ /** @see {@link resetSorter} */
1142
1197
  resetSorter,
1143
- /** 滚动至 */
1198
+ /** @see {@link scrollTo} */
1144
1199
  scrollTo,
1145
- /** 获取表格数据 */
1200
+ /** @see {@link getTableData} */
1146
1201
  getTableData,
1147
1202
  });
1148
1203
  </script>
@@ -15,6 +15,7 @@
15
15
  --border-width: 1px;
16
16
  --td-bgc: #fff;
17
17
  --td-hover-color: #71a2fd;
18
+ --td-active-color: #386ccc;
18
19
  --th-bgc: #fafafc;
19
20
  --th-color: #272841;
20
21
  --tr-active-bgc: rgb(230, 247, 255);
@@ -62,6 +63,7 @@
62
63
  --th-color: #C0C0D1;
63
64
  --td-bgc: #1b1b24;
64
65
  --td-hover-color: #70a6ff;
66
+ --td-active-color: #386ccc;
65
67
  --border-color: #292933;
66
68
  --tr-active-bgc: #283f63;
67
69
  --tr-hover-bgc: #1a2b46;
@@ -167,6 +169,11 @@
167
169
  box-shadow: inset 0 0 0 2px var(--td-hover-color);
168
170
  }
169
171
 
172
+ /* 单元格高亮 */
173
+ &.cell-active tbody td.active{
174
+ box-shadow: inset 0 0 0 2px var(--td-active-color);
175
+ }
176
+
170
177
  /* td 溢出*/
171
178
  &.text-overflow {
172
179
  .table-cell-wrapper {