vxe-table 4.1.6 → 4.1.9

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.
Files changed (53) hide show
  1. package/es/button/src/button.js +14 -14
  2. package/es/edit/src/hook.js +3 -3
  3. package/es/export/src/hook.js +17 -6
  4. package/es/filter/src/hook.js +20 -1
  5. package/es/grid/src/grid.js +6 -2
  6. package/es/table/src/body.js +11 -14
  7. package/es/table/src/cell.js +16 -14
  8. package/es/table/src/props.js +6 -6
  9. package/es/table/src/table.js +102 -89
  10. package/es/table/src/util.js +3 -0
  11. package/es/tools/dom.js +2 -8
  12. package/es/v-x-e-table/src/conf.js +3 -0
  13. package/lib/button/src/button.js +15 -14
  14. package/lib/button/src/button.min.js +1 -1
  15. package/lib/edit/src/hook.js +3 -0
  16. package/lib/edit/src/hook.min.js +1 -1
  17. package/lib/export/src/hook.js +25 -10
  18. package/lib/export/src/hook.min.js +1 -1
  19. package/lib/filter/src/hook.js +23 -0
  20. package/lib/filter/src/hook.min.js +1 -1
  21. package/lib/grid/src/grid.js +6 -3
  22. package/lib/grid/src/grid.min.js +1 -1
  23. package/lib/index.umd.js +307 -208
  24. package/lib/index.umd.min.js +1 -1
  25. package/lib/table/src/body.js +8 -16
  26. package/lib/table/src/body.min.js +1 -1
  27. package/lib/table/src/cell.js +16 -16
  28. package/lib/table/src/cell.min.js +1 -1
  29. package/lib/table/src/props.js +6 -6
  30. package/lib/table/src/table.js +158 -114
  31. package/lib/table/src/table.min.js +1 -1
  32. package/lib/table/src/util.js +7 -0
  33. package/lib/table/src/util.min.js +1 -1
  34. package/lib/tools/dom.js +2 -9
  35. package/lib/tools/dom.min.js +1 -1
  36. package/lib/v-x-e-table/src/conf.js +3 -0
  37. package/lib/v-x-e-table/src/conf.min.js +1 -1
  38. package/package.json +1 -1
  39. package/packages/button/src/button.ts +14 -14
  40. package/packages/edit/src/hook.ts +3 -3
  41. package/packages/export/src/hook.ts +17 -6
  42. package/packages/filter/src/hook.ts +20 -1
  43. package/packages/grid/src/grid.ts +6 -2
  44. package/packages/table/src/body.ts +11 -14
  45. package/packages/table/src/cell.ts +16 -14
  46. package/packages/table/src/props.ts +6 -6
  47. package/packages/table/src/table.ts +102 -89
  48. package/packages/table/src/util.ts +4 -0
  49. package/packages/tools/dom.ts +2 -7
  50. package/packages/v-x-e-table/src/conf.ts +3 -0
  51. package/types/filter.d.ts +5 -0
  52. package/types/plugins/pro.d.ts +5 -0
  53. package/types/table.d.ts +12 -2
@@ -11,7 +11,7 @@ import Cell from './cell'
11
11
  import TableBodyComponent from './body'
12
12
  import tableProps from './props'
13
13
  import tableEmits from './emits'
14
- import { getRowUniqueId, clearTableAllStatus, getRowkey, getRowid, rowToVisible, colToVisible, getCellValue, setCellValue, handleFieldOrColumn, restoreScrollLocation, restoreScrollListener, XEBodyScrollElement } from './util'
14
+ import { getRowUniqueId, clearTableAllStatus, getRowkey, getRowid, rowToVisible, colToVisible, getCellValue, setCellValue, handleFieldOrColumn, toTreePathSeq, restoreScrollLocation, restoreScrollListener, XEBodyScrollElement } from './util'
15
15
 
16
16
  import { VxeGridConstructor, VxeGridPrivateMethods, VxeTableConstructor, TableReactData, TableInternalData, VxeTablePropTypes, VxeToolbarConstructor, VxeTooltipInstance, TablePrivateMethods, VxeTablePrivateRef, VxeTablePrivateComputed, VxeTablePrivateMethods, VxeTableMethods, TableMethods, VxeMenuPanelInstance, VxeTableDefines, VxeTableProps } from '../../../types/all'
17
17
 
@@ -271,8 +271,9 @@ export default defineComponent({
271
271
  tableFullColumn: [],
272
272
  // 渲染所有列
273
273
  visibleColumn: [],
274
- // 缓存数据集
274
+ // 总的缓存数据集
275
275
  fullAllDataRowIdData: {},
276
+ // 渲染中缓存数据
276
277
  fullDataRowIdData: {},
277
278
  fullColumnIdData: {},
278
279
  fullColumnFieldData: {},
@@ -1130,17 +1131,49 @@ export default defineComponent({
1130
1131
  }
1131
1132
  }
1132
1133
 
1134
+ /**
1135
+ * 预编译
1136
+ * 对渲染中的数据提前解析序号及索引。牺牲提前编译耗时换取渲染中额外损耗,使运行时更加流畅
1137
+ */
1133
1138
  const updateAfterDataIndex = () => {
1134
- const { afterFullData, fullDataRowIdData } = internalData
1135
- afterFullData.forEach((row, _index) => {
1136
- const rowid = getRowid($xetable, row)
1137
- const rest = fullDataRowIdData[rowid]
1138
- if (rest) {
1139
- rest._index = _index
1140
- } else {
1141
- fullDataRowIdData[rowid] = { row, rowid, index: -1, $index: -1, _index, items: [], parent: null, level: 0 }
1142
- }
1143
- })
1139
+ const { treeConfig } = props
1140
+ const { afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
1141
+ const { treeFullData } = internalData
1142
+ const treeOpts = computeTreeOpts.value
1143
+ if (treeConfig) {
1144
+ XEUtils.eachTree(treeFullData, (row, index, items, path) => {
1145
+ const rowid = getRowid($xetable, row)
1146
+ const allrest = fullAllDataRowIdData[rowid]
1147
+ const fullrest = fullDataRowIdData[rowid]
1148
+ const seq = path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
1149
+ if (allrest) {
1150
+ allrest.seq = seq
1151
+ }
1152
+ if (fullrest) {
1153
+ fullrest.seq = seq
1154
+ } else {
1155
+ fullAllDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1156
+ fullDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1157
+ }
1158
+ }, treeOpts)
1159
+ } else {
1160
+ afterFullData.forEach((row, index) => {
1161
+ const rowid = getRowid($xetable, row)
1162
+ const allrest = fullAllDataRowIdData[rowid]
1163
+ const fullrest = fullDataRowIdData[rowid]
1164
+ const seq = index + 1
1165
+ if (allrest) {
1166
+ allrest.seq = seq
1167
+ }
1168
+ if (fullrest) {
1169
+ fullrest.seq = seq
1170
+ fullrest._index = index
1171
+ } else {
1172
+ fullAllDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1173
+ fullDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1174
+ }
1175
+ })
1176
+ }
1144
1177
  }
1145
1178
 
1146
1179
  /**
@@ -2062,11 +2095,11 @@ export default defineComponent({
2062
2095
  tableMethods.clearMergeFooterItems()
2063
2096
  }
2064
2097
  reactData.scrollXLoad = scrollXLoad
2065
- visibleColumn.forEach((column, _index) => {
2098
+ visibleColumn.forEach((column, index) => {
2066
2099
  const colid = column.id
2067
2100
  const rest = fullColumnIdData[colid]
2068
2101
  if (rest) {
2069
- rest._index = _index
2102
+ rest._index = index
2070
2103
  }
2071
2104
  })
2072
2105
  internalData.visibleColumn = visibleColumn
@@ -2224,6 +2257,33 @@ export default defineComponent({
2224
2257
  }
2225
2258
  }
2226
2259
 
2260
+ const createGetRowCacheProp = (prop: 'seq' | 'index' | '_index' | '$index') => {
2261
+ return function (row: any) {
2262
+ const { fullDataRowIdData } = internalData
2263
+ if (row) {
2264
+ const rowid = getRowid($xetable, row)
2265
+ const rest = fullDataRowIdData[rowid]
2266
+ if (rest) {
2267
+ return rest[prop]
2268
+ }
2269
+ }
2270
+ return -1
2271
+ }
2272
+ }
2273
+
2274
+ const createGetColumnCacheProp = (prop: 'index' | '_index' | '$index') => {
2275
+ return function (column: VxeTableDefines.ColumnInfo) {
2276
+ const { fullColumnIdData } = internalData
2277
+ if (column) {
2278
+ const rest = fullColumnIdData[column.id]
2279
+ if (rest) {
2280
+ return rest[prop]
2281
+ }
2282
+ }
2283
+ return -1
2284
+ }
2285
+ }
2286
+
2227
2287
  const debounceScrollY = XEUtils.debounce(function (evnt: Event) {
2228
2288
  loadScrollYData(evnt)
2229
2289
  }, 20, { leading: false, trailing: true })
@@ -2349,7 +2409,7 @@ export default defineComponent({
2349
2409
  }
2350
2410
  XEUtils.eachTree(rows, (childRow, index, items, path, parent, nodes) => {
2351
2411
  const rowid = getRowid($xetable, childRow)
2352
- const rest = { row: childRow, rowid, index: -1, _index: -1, $index: -1, items, parent, level: parentLevel + nodes.length }
2412
+ const rest = { row: childRow, rowid, seq: -1, index: -1, _index: -1, $index: -1, items, parent, level: parentLevel + nodes.length }
2353
2413
  fullDataRowIdData[rowid] = rest
2354
2414
  fullAllDataRowIdData[rowid] = rest
2355
2415
  }, treeOpts)
@@ -2410,93 +2470,41 @@ export default defineComponent({
2410
2470
  }
2411
2471
  return null
2412
2472
  },
2473
+ /**
2474
+ * 根据 row 获取序号
2475
+ * @param {Row} row 行对象
2476
+ */
2477
+ getRowSeq: createGetRowCacheProp('seq'),
2413
2478
  /**
2414
2479
  * 根据 row 获取相对于 data 中的索引
2415
2480
  * @param {Row} row 行对象
2416
2481
  */
2417
- getRowIndex (row) {
2418
- const { fullDataRowIdData } = internalData
2419
- if (row) {
2420
- const rowid = getRowid($xetable, row)
2421
- const rest = fullDataRowIdData[rowid]
2422
- if (rest) {
2423
- return rest.index
2424
- }
2425
- }
2426
- return -1
2427
- },
2482
+ getRowIndex: createGetRowCacheProp('index') as ((row: any) => number),
2428
2483
  /**
2429
2484
  * 根据 row 获取相对于当前数据中的索引
2430
2485
  * @param {Row} row 行对象
2431
2486
  */
2432
- getVTRowIndex (row) {
2433
- const { fullDataRowIdData } = internalData
2434
- if (row) {
2435
- const rowid = getRowid($xetable, row)
2436
- const rest = fullDataRowIdData[rowid]
2437
- if (rest) {
2438
- return rest._index
2439
- }
2440
- }
2441
- return -1
2442
- },
2487
+ getVTRowIndex: createGetRowCacheProp('_index') as ((row: any) => number),
2443
2488
  /**
2444
2489
  * 根据 row 获取渲染中的虚拟索引
2445
2490
  * @param {Row} row 行对象
2446
2491
  */
2447
- getVMRowIndex (row) {
2448
- const { fullDataRowIdData } = internalData
2449
- if (row) {
2450
- const rowid = getRowid($xetable, row)
2451
- const rest = fullDataRowIdData[rowid]
2452
- if (rest) {
2453
- return rest.$index
2454
- }
2455
- }
2456
- return -1
2457
- },
2492
+ getVMRowIndex: createGetRowCacheProp('$index') as ((row: any) => number),
2458
2493
  /**
2459
2494
  * 根据 column 获取相对于 columns 中的索引
2460
2495
  * @param {ColumnInfo} column 列配置
2461
2496
  */
2462
- getColumnIndex (column) {
2463
- const { fullColumnIdData } = internalData
2464
- if (column) {
2465
- const rest = fullColumnIdData[column.id]
2466
- if (rest) {
2467
- return rest.index
2468
- }
2469
- }
2470
- return -1
2471
- },
2497
+ getColumnIndex: createGetColumnCacheProp('index'),
2472
2498
  /**
2473
2499
  * 根据 column 获取相对于当前表格列中的索引
2474
2500
  * @param {ColumnInfo} column 列配置
2475
2501
  */
2476
- getVTColumnIndex (column) {
2477
- const { fullColumnIdData } = internalData
2478
- if (column) {
2479
- const rest = fullColumnIdData[column.id]
2480
- if (rest) {
2481
- return rest._index
2482
- }
2483
- }
2484
- return -1
2485
- },
2502
+ getVTColumnIndex: createGetColumnCacheProp('_index'),
2486
2503
  /**
2487
2504
  * 根据 column 获取渲染中的虚拟索引
2488
2505
  * @param {ColumnInfo} column 列配置
2489
2506
  */
2490
- getVMColumnIndex (column) {
2491
- const { fullColumnIdData } = internalData
2492
- if (column) {
2493
- const rest = fullColumnIdData[column.id]
2494
- if (rest) {
2495
- return rest.$index
2496
- }
2497
- }
2498
- return -1
2499
- },
2507
+ getVMColumnIndex: createGetColumnCacheProp('$index'),
2500
2508
  /**
2501
2509
  * 创建 data 对象
2502
2510
  * 对于某些特殊场景可能会用到,会自动对数据的字段名进行检测,如果不存在就自动定义
@@ -3230,7 +3238,7 @@ export default defineComponent({
3230
3238
  return selectRow
3231
3239
  }
3232
3240
  } else {
3233
- if (afterFullData.indexOf(selectRow) > -1) {
3241
+ if ($xetable.findRowIndexOf(afterFullData, selectRow) > -1) {
3234
3242
  return selectRow
3235
3243
  }
3236
3244
  }
@@ -3993,6 +4001,7 @@ export default defineComponent({
3993
4001
  const { mouseConfig, keyboardConfig } = props
3994
4002
  const { filterStore, ctxMenuStore, editStore } = reactData
3995
4003
  const mouseOpts = computeMouseOpts.value
4004
+ const keyboardOpts = computeKeyboardOpts.value
3996
4005
  const { actived } = editStore
3997
4006
  const isEsc = hasEventKey(evnt, EVENT_KEYS.ESCAPE)
3998
4007
  if (isEsc) {
@@ -4006,13 +4015,15 @@ export default defineComponent({
4006
4015
  $xetable.closeMenu()
4007
4016
  }
4008
4017
  tableMethods.closeFilter()
4009
- // 如果是激活编辑状态,则取消编辑
4010
- if (actived.row) {
4011
- const params = actived.args
4012
- $xetable.clearActived(evnt)
4013
- // 如果配置了选中功能,则为选中状态
4014
- if (mouseOpts.selected) {
4015
- nextTick(() => $xetable.handleSelected(params, evnt))
4018
+ if (keyboardConfig && keyboardOpts.isEsc) {
4019
+ // 如果是激活编辑状态,则取消编辑
4020
+ if (actived.row) {
4021
+ const params = actived.args
4022
+ $xetable.clearActived(evnt)
4023
+ // 如果配置了选中功能,则为选中状态
4024
+ if (mouseOpts.selected) {
4025
+ nextTick(() => $xetable.handleSelected(params, evnt))
4026
+ }
4016
4027
  }
4017
4028
  }
4018
4029
  }
@@ -4076,7 +4087,7 @@ export default defineComponent({
4076
4087
  $xetable.closeMenu()
4077
4088
  }
4078
4089
  tableMethods.closeFilter()
4079
- if (actived.row) {
4090
+ if (keyboardConfig && keyboardOpts.isEsc) {
4080
4091
  // 如果是激活编辑状态,则取消编辑
4081
4092
  if (actived.row) {
4082
4093
  const params = actived.args
@@ -4461,8 +4472,10 @@ export default defineComponent({
4461
4472
  let { fullDataRowIdData, fullAllDataRowIdData, tableFullData, treeFullData } = internalData
4462
4473
  const rowkey = getRowkey($xetable)
4463
4474
  const isLazy = treeConfig && treeOpts.lazy
4464
- const handleCache = (row: any, index: any, items: any, path?: any, parent?: any, nodes?: any[]) => {
4475
+ const handleCache = (row: any, index: any, items: any, path?: any[], parent?: any, nodes?: any[]) => {
4465
4476
  let rowid = getRowid($xetable, row)
4477
+ const seq = treeConfig && path ? toTreePathSeq(path) : index + 1
4478
+ const level = nodes ? nodes.length - 1 : 0
4466
4479
  if (eqEmptyValue(rowid)) {
4467
4480
  rowid = getRowUniqueId()
4468
4481
  XEUtils.set(row, rowkey, rowid)
@@ -4470,7 +4483,7 @@ export default defineComponent({
4470
4483
  if (isLazy && row[treeOpts.hasChild] && XEUtils.isUndefined(row[treeOpts.children])) {
4471
4484
  row[treeOpts.children] = null
4472
4485
  }
4473
- const rest = { row, rowid, index: treeConfig && parent ? -1 : index, _index: -1, $index: -1, items, parent, level: nodes ? nodes.length - 1 : 0 }
4486
+ const rest = { row, rowid, seq, index: treeConfig && parent ? -1 : index, _index: -1, $index: -1, items, parent, level }
4474
4487
  if (isSource) {
4475
4488
  fullDataRowIdData[rowid] = rest
4476
4489
  }
@@ -98,6 +98,10 @@ export function toFilters (filters: any) {
98
98
  return filters
99
99
  }
100
100
 
101
+ export function toTreePathSeq (path: any[]) {
102
+ return path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
103
+ }
104
+
101
105
  export function getCellValue (row: any, column: any) {
102
106
  return XEUtils.get(row, column.property)
103
107
  }
@@ -142,12 +142,7 @@ export function scrollToView (elem: any) {
142
142
  }
143
143
 
144
144
  export function triggerEvent (targetElem: Element, type: string) {
145
- let evnt
146
- if (typeof Event === 'function') {
147
- evnt = new Event(type)
148
- } else {
149
- evnt = document.createEvent('Event')
150
- evnt.initEvent(type, true, true)
145
+ if (targetElem) {
146
+ targetElem.dispatchEvent(new Event(type))
151
147
  }
152
- targetElem.dispatchEvent(evnt)
153
148
  }
@@ -93,6 +93,9 @@ const GlobalConfig: VXETableGlobalConfig = {
93
93
  mouseConfig: {
94
94
  extension: true
95
95
  },
96
+ keyboardConfig: {
97
+ isEsc: true
98
+ },
96
99
  areaConfig: {
97
100
  selectCellByHeader: true
98
101
  },
package/types/filter.d.ts CHANGED
@@ -32,6 +32,11 @@ export interface VxeFilterPanel {
32
32
  }
33
33
 
34
34
  export interface TableFilterMethods {
35
+ /**
36
+ * 手动弹出筛选
37
+ * @param fieldOrColumn
38
+ */
39
+ openFilter(fieldOrColumn: VxeColumnPropTypes.Field | VxeTableDefines.ColumnInfo):Promise<any>;
35
40
  /**
36
41
  * 用于 filters,修改筛选列表
37
42
  * 在筛选条件更新之后可以调用 updateData 函数处理表格数据
@@ -81,6 +81,11 @@ declare module '../table' {
81
81
  interface VxeTablePrivateMethods extends VxeTableProPrivateMethods { }
82
82
  }
83
83
 
84
+ declare module '../grid' {
85
+ interface VxeGridMethods extends VxeTableProMethods { }
86
+ interface VxeGridPrivateMethods extends VxeTableProPrivateMethods { }
87
+ }
88
+
84
89
  export interface VXETableProClipboard {
85
90
  text?: string;
86
91
  html?: string;
package/types/table.d.ts CHANGED
@@ -162,6 +162,11 @@ export interface TablePublicMethods {
162
162
  index: number;
163
163
  parent?: VxeTableDefines.ColumnInfo;
164
164
  } | null;
165
+ /**
166
+ * 根据 row 获取行的序号
167
+ * @param row 行对象
168
+ */
169
+ getRowSeq(row: any): string | number;
165
170
  /**
166
171
  * 根据 row 获取相对于 data 中的索引
167
172
  * @param row 行对象
@@ -969,6 +974,7 @@ export interface TableInternalData {
969
974
  [key: string]: {
970
975
  row: any;
971
976
  rowid: string;
977
+ seq: string | number;
972
978
  index: number;
973
979
  $index: number;
974
980
  _index: number;
@@ -989,6 +995,7 @@ export interface TableInternalData {
989
995
  [key: string]: {
990
996
  row: any;
991
997
  rowid: string;
998
+ seq: string | number;
992
999
  index: number;
993
1000
  $index: number;
994
1001
  _index: number;
@@ -1555,6 +1562,10 @@ export namespace VxeTablePropTypes {
1555
1562
  * 是否开启非编辑状态下,上下左右移动功能
1556
1563
  */
1557
1564
  isArrow?: boolean;
1565
+ /**
1566
+ * 是否开启Esc键退出编辑功能
1567
+ */
1568
+ isEsc?: boolean;
1558
1569
  /**
1559
1570
  * 是否开启删除键功能
1560
1571
  */
@@ -2143,8 +2154,7 @@ export namespace VxeTableDefines {
2143
2154
  }
2144
2155
  export interface CellRenderBodyParams {
2145
2156
  $table: VxeTableConstructor & VxeTablePrivateMethods;
2146
- $seq: string;
2147
- seq: number;
2157
+ seq: string | number;
2148
2158
  rowid: string;
2149
2159
  row: any;
2150
2160
  rowIndex: number;