vxe-table 3.4.2 → 3.4.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.
@@ -464,16 +464,12 @@ const Methods = {
464
464
  const oRow = tableSourceData[rowIndex]
465
465
  if (oRow && row) {
466
466
  if (field) {
467
- XEUtils.set(oRow, field, XEUtils.get(record || row, field))
467
+ const newValue = XEUtils.get(record || row, field)
468
+ XEUtils.set(row, field, newValue)
469
+ XEUtils.set(oRow, field, newValue)
468
470
  } else {
469
- if (record) {
470
- tableSourceData[rowIndex] = record
471
- XEUtils.clear(row, undefined)
472
- Object.assign(row, this.defineField(Object.assign({}, record)))
473
- this.cacheRowMap(true)
474
- } else {
475
- XEUtils.destructuring(oRow, XEUtils.clone(row, true))
476
- }
471
+ const newRecord = XEUtils.clone({ ...record }, true)
472
+ XEUtils.destructuring(oRow, Object.assign(row, newRecord))
477
473
  }
478
474
  }
479
475
  this.tableData = tableData.slice(0)
@@ -2135,7 +2131,7 @@ const Methods = {
2135
2131
  // 该行为只对当前激活的表格有效
2136
2132
  if (this.isActivated) {
2137
2133
  this.preventEvent(evnt, 'event.keydown', null, () => {
2138
- const { filterStore, isCtxMenu, ctxMenuStore, editStore, editOpts, editConfig, mouseConfig, mouseOpts, keyboardConfig, keyboardOpts, treeConfig, treeOpts, highlightCurrentRow, currentRow, bodyCtxMenu } = this
2134
+ const { filterStore, isCtxMenu, ctxMenuStore, editStore, editOpts, editConfig, mouseConfig, mouseOpts, keyboardConfig, keyboardOpts, treeConfig, treeOpts, highlightCurrentRow, currentRow, bodyCtxMenu, rowOpts } = this
2139
2135
  const { selected, actived } = editStore
2140
2136
  const { keyCode } = evnt
2141
2137
  const isBack = keyCode === 8
@@ -2198,7 +2194,7 @@ const Methods = {
2198
2194
  this.keyCtxTimeout = setTimeout(() => {
2199
2195
  this._keyCtx = false
2200
2196
  }, 1000)
2201
- } else if (isEnter && !hasAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && highlightCurrentRow && currentRow))) {
2197
+ } else if (isEnter && !hasAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow))) {
2202
2198
  // 退出选中
2203
2199
  if (hasCtrlKey) {
2204
2200
  // 如果是激活编辑状态,则取消编辑
@@ -2227,7 +2223,7 @@ const Methods = {
2227
2223
  this.moveSelected(targetArgs, isLeftArrow, false, isRightArrow, true, evnt)
2228
2224
  }
2229
2225
  }
2230
- } else if (treeConfig && highlightCurrentRow && currentRow) {
2226
+ } else if (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2231
2227
  // 如果是树形表格当前行回车移动到子节点
2232
2228
  const childrens = currentRow[treeOpts.children]
2233
2229
  if (childrens && childrens.length) {
@@ -2245,7 +2241,7 @@ const Methods = {
2245
2241
  // 如果按下了方向键
2246
2242
  if (selected.row && selected.column) {
2247
2243
  this.moveSelected(selected.args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt)
2248
- } else if ((isUpArrow || isDwArrow) && highlightCurrentRow) {
2244
+ } else if ((isUpArrow || isDwArrow) && (rowOpts.isCurrent || highlightCurrentRow)) {
2249
2245
  // 当前行按键上下移动
2250
2246
  this.moveCurrentRow(isUpArrow, isDwArrow, evnt)
2251
2247
  }
@@ -2257,7 +2253,7 @@ const Methods = {
2257
2253
  } else if (actived.row || actived.column) {
2258
2254
  this.moveTabSelected(actived.args, hasShiftKey, evnt)
2259
2255
  }
2260
- } else if (keyboardConfig && (isDel || (treeConfig && highlightCurrentRow && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
2256
+ } else if (keyboardConfig && (isDel || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
2261
2257
  if (!isEditStatus) {
2262
2258
  const { delMethod, backMethod } = keyboardOpts
2263
2259
  // 如果是删除键
@@ -2289,7 +2285,7 @@ const Methods = {
2289
2285
  // 如果按下 del 键,更新表尾数据
2290
2286
  this.updateFooter()
2291
2287
  }
2292
- } else if (isBack && keyboardOpts.isArrow && treeConfig && highlightCurrentRow && currentRow) {
2288
+ } else if (isBack && keyboardOpts.isArrow && treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2293
2289
  // 如果树形表格回退键关闭当前行返回父节点
2294
2290
  const { parent: parentRow } = XEUtils.findTree(this.afterFullData, item => item === currentRow, treeOpts)
2295
2291
  if (parentRow) {
@@ -2927,6 +2923,16 @@ const Methods = {
2927
2923
  const { fullDataRowIdData, afterFullData, checkboxReserveRowMap, checkboxOpts, treeConfig, treeOpts } = this
2928
2924
  const reserveSelection = []
2929
2925
  if (checkboxOpts.reserve) {
2926
+ const afterFullIdMaps = {}
2927
+ if (treeConfig) {
2928
+ XEUtils.eachTree(afterFullData, row => {
2929
+ afterFullIdMaps[getRowid(this, row)] = 1
2930
+ }, treeOpts)
2931
+ } else {
2932
+ afterFullData.forEach(row => {
2933
+ afterFullIdMaps[getRowid(this, row)] = 1
2934
+ })
2935
+ }
2930
2936
  XEUtils.each(checkboxReserveRowMap, (oldRow, oldRowid) => {
2931
2937
  if (oldRow) {
2932
2938
  if (isFull) {
@@ -2934,14 +2940,8 @@ const Methods = {
2934
2940
  reserveSelection.push(oldRow)
2935
2941
  }
2936
2942
  } else {
2937
- if (treeConfig) {
2938
- if (!XEUtils.findTree(afterFullData, row => getRowid(this, row) === oldRowid, treeOpts)) {
2939
- reserveSelection.push(oldRow)
2940
- }
2941
- } else {
2942
- if (!afterFullData.some(row => getRowid(this, row) === oldRowid)) {
2943
- reserveSelection.push(oldRow)
2944
- }
2943
+ if (!afterFullIdMaps[oldRowid]) {
2944
+ reserveSelection.push(oldRow)
2945
2945
  }
2946
2946
  }
2947
2947
  }
@@ -3052,11 +3052,11 @@ const Methods = {
3052
3052
  * @param {Row} row 行对象
3053
3053
  */
3054
3054
  setCurrentRow (row) {
3055
- const { $el } = this
3055
+ const { $el, rowOpts } = this
3056
3056
  this.clearCurrentRow()
3057
3057
  this.clearCurrentColumn()
3058
3058
  this.currentRow = row
3059
- if (this.highlightCurrentRow) {
3059
+ if (rowOpts.isCurrent || this.highlightCurrentRow) {
3060
3060
  if ($el) {
3061
3061
  XEUtils.arrayEach($el.querySelectorAll(`[rowid="${getRowid(this, row)}"]`), elem => addClass(elem, 'row--current'))
3062
3062
  }
@@ -3102,7 +3102,7 @@ const Methods = {
3102
3102
  * 用于当前行,获取当前行的数据
3103
3103
  */
3104
3104
  getCurrentRecord () {
3105
- return this.highlightCurrentRow ? this.currentRow : null
3105
+ return this.rowOpts.isCurrent || this.highlightCurrentRow ? this.currentRow : null
3106
3106
  },
3107
3107
  /**
3108
3108
  * 用于单选行,获取当已选中的数据
@@ -3164,7 +3164,7 @@ const Methods = {
3164
3164
  this.triggerSortEvent(evnt, column, getNextSortOrder(this, column))
3165
3165
  }
3166
3166
  this.emitEvent('header-cell-click', Object.assign({ triggerResizable, triggerSort, triggerFilter, cell }, params), evnt)
3167
- if (this.highlightCurrentColumn) {
3167
+ if (this.columnOpts.isCurrent || this.highlightCurrentColumn) {
3168
3168
  return this.setCurrentColumn(column)
3169
3169
  }
3170
3170
  return this.$nextTick()
@@ -3173,7 +3173,7 @@ const Methods = {
3173
3173
  this.emitEvent('header-cell-dblclick', Object.assign({ cell: evnt.currentTarget }, params), evnt)
3174
3174
  },
3175
3175
  getCurrentColumn () {
3176
- return this.highlightCurrentColumn ? this.currentColumn : null
3176
+ return this.columnOpts.isCurrent || this.highlightCurrentColumn ? this.currentColumn : null
3177
3177
  },
3178
3178
  /**
3179
3179
  * 用于当前列,设置某列行为高亮状态
@@ -3220,7 +3220,7 @@ const Methods = {
3220
3220
  * 如果是双击模式,则单击后选中状态
3221
3221
  */
3222
3222
  triggerCellClickEvent (evnt, params) {
3223
- const { highlightCurrentRow, editStore, radioOpts, expandOpts, treeOpts, editConfig, editOpts, checkboxOpts } = this
3223
+ const { highlightCurrentRow, editStore, radioOpts, expandOpts, treeOpts, editConfig, editOpts, checkboxOpts, rowOpts } = this
3224
3224
  const { actived } = editStore
3225
3225
  const { row, column } = params
3226
3226
  const { type, treeNode } = column
@@ -3247,7 +3247,7 @@ const Methods = {
3247
3247
  if (!triggerTreeNode) {
3248
3248
  if (!triggerExpandNode) {
3249
3249
  // 如果是高亮行
3250
- if (highlightCurrentRow) {
3250
+ if (rowOpts.isCurrent || highlightCurrentRow) {
3251
3251
  if (!triggerCheckbox && !triggerRadio) {
3252
3252
  this.triggerCurrentRowEvent(evnt, params)
3253
3253
  }
@@ -3843,8 +3843,10 @@ const Methods = {
3843
3843
  updateVirtualTreeData () {
3844
3844
  const { scrollYLoad: oldScrollYLoad, treeExpandeds, treeOpts, treeFullData } = this
3845
3845
  const fullData = []
3846
+ const expandMaps = new Map()
3846
3847
  XEUtils.eachTree(treeFullData, (row, index, items, path, parent) => {
3847
- if (!parent || treeExpandeds.indexOf(parent) > -1) {
3848
+ if (!parent || (expandMaps.has(parent) && treeExpandeds.indexOf(parent) > -1)) {
3849
+ expandMaps.set(row, 1)
3848
3850
  fullData.push(row)
3849
3851
  }
3850
3852
  }, treeOpts)
@@ -976,7 +976,9 @@ export default {
976
976
  ctxMenuStore,
977
977
  ctxMenuOpts,
978
978
  footerTableData,
979
- hasTip
979
+ hasTip,
980
+ columnOpts,
981
+ rowOpts
980
982
  } = this
981
983
  const { leftList, rightList } = columnStore
982
984
  return h('div', {
@@ -985,8 +987,8 @@ export default {
985
987
  'cell--highlight': highlightCell,
986
988
  'cell--selected': mouseConfig && mouseOpts.selected,
987
989
  'cell--area': mouseConfig && mouseOpts.area,
988
- 'row--highlight': highlightHoverRow,
989
- 'column--highlight': highlightHoverColumn,
990
+ 'row--highlight': rowOpts.isHover || highlightHoverRow,
991
+ 'column--highlight': columnOpts.isHover || highlightHoverColumn,
990
992
  'is--header': showHeader,
991
993
  'is--footer': showFooter,
992
994
  'is--group': isGroup,
@@ -11,6 +11,7 @@ export default {
11
11
  showHeader: true,
12
12
  animat: true,
13
13
  delayHover: 250,
14
+ autoResize: true,
14
15
  // keepSource: false,
15
16
  // showOverflow: null,
16
17
  // showHeaderOverflow: null,
@@ -18,7 +19,6 @@ export default {
18
19
  // resizeInterval: 500,
19
20
  // size: null,
20
21
  // zIndex: null,
21
- // autoResize: false,
22
22
  // stripe: false,
23
23
  // border: false,
24
24
  // round: false,
@@ -151,21 +151,21 @@ export default {
151
151
  const ruleProps = Object.keys(validRest)
152
152
  return this.$nextTick().then(() => {
153
153
  if (ruleProps.length) {
154
- return Promise.reject(validRest[ruleProps[0]][0])
154
+ return validRest[ruleProps[0]][0]
155
155
  }
156
156
  if (cb) {
157
157
  cb()
158
158
  }
159
159
  })
160
160
  }).catch(firstErrParams => {
161
- return new Promise((resolve, reject) => {
161
+ return new Promise((resolve) => {
162
162
  const finish = () => {
163
163
  this.$nextTick(() => {
164
164
  if (cb) {
165
165
  cb(validRest)
166
166
  resolve()
167
167
  } else {
168
- reject(validRest)
168
+ resolve(validRest)
169
169
  }
170
170
  })
171
171
  }
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as VXETableExport from './all'
2
2
 
3
3
  /**
4
- * 一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
4
+ * 一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
5
5
  */
6
6
  declare const VXETable: typeof VXETableExport
7
7
 
package/types/table.d.ts CHANGED
@@ -803,9 +803,12 @@ export declare class Table extends VXETableComponent {
803
803
  */
804
804
  insert(records: RecordInfo | RecordInfo[]): Promise<{ row: RowInfo, rows: RowInfo[] }>;
805
805
  /**
806
- * 往表格插入临时数据,从指定位置插入一行或多行;第二个参数:row 指定位置、null从第一行插入、-1 从最后插入
807
- * @param records 新数据
808
- * @param row 指定行
806
+ * 往表格指定行中插入临时数据
807
+ * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标节点顶部
808
+ * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标节点底部
809
+ * 如果 row 为有效行则插入到该行的位置,如果为树结构,则有插入到效的目标节点该行的位置
810
+ * @param {Object/Array} records 新的数据
811
+ * @param {Row} row 指定行
809
812
  */
810
813
  insertAt(records: RecordInfo | RecordInfo[], row: RowInfo | -1 | null): Promise<{ row: RowInfo, rows: RowInfo[] }>;
811
814
  /**
@@ -859,9 +862,9 @@ export declare class Table extends VXETableComponent {
859
862
  */
860
863
  clearActived(): Promise<any>;
861
864
  /**
862
- * 用于 mouse-config.area,用于清除鼠标选择的区域
865
+ * 用于 mouse-config.area,用于清除鼠标选择的区域,可以指定清除的区域
863
866
  */
864
- clearCellAreas(): Promise<any>;
867
+ clearCellAreas(area?: number | MouseCellArea): Promise<any>;
865
868
  /**
866
869
  * 用于 edit-config,获取已激活的行数据
867
870
  */
@@ -901,9 +904,9 @@ export declare class Table extends VXETableComponent {
901
904
  * @param areaConfigs 指定区域
902
905
  */
903
906
  setCellAreas(areaConfigs: CellAreaConfig[], activeArea?: {
904
- area?: MouseCellArea;
905
- column: ColumnInfo;
906
- row: RowInfo;
907
+ area?: number | MouseCellArea;
908
+ column?: number | ColumnInfo;
909
+ row?: number | RowInfo;
907
910
  }): Promise<any>;
908
911
  /**
909
912
  * 用于 mouse-config.area,设置活动的区域的单元格
@@ -911,8 +914,8 @@ export declare class Table extends VXETableComponent {
911
914
  */
912
915
  setActiveCellArea(activeArea: {
913
916
  area: MouseCellArea;
914
- column: ColumnInfo;
915
- row: RowInfo;
917
+ column: number | ColumnInfo;
918
+ row: number | RowInfo;
916
919
  }): Promise<any>;
917
920
  /**
918
921
  * 临时合并单元格,如果为数组则合并多个
@@ -27,6 +27,8 @@ export interface RendererMapOptions {
27
27
  renderFilter?(h: CreateElement, renderOpts: ColumnFilterRenderOptions, params: ColumnFilterRenderParams): VNode[] | string[];
28
28
  filterMethod?(params: ColumnFilterMethodParams): boolean;
29
29
  filterResetMethod?(params: ColumnFilterResetParams): void;
30
+ // 默认行为
31
+ defaultFilterMethod?(params: ColumnFilterMethodParams): boolean;
30
32
 
31
33
  // 单元格渲染
32
34
  renderHeader?(h: CreateElement, renderOpts: ColumnCellRenderOptions | ColumnEditRenderOptions, params: ColumnCellRenderParams | ColumnEditRenderParams): VNode[] | string[];
@@ -66,7 +68,7 @@ export class RenderOptions {
66
68
  /**
67
69
  * 渲染器名称
68
70
  */
69
- name: string;
71
+ name?: string;
70
72
  /**
71
73
  * 目标组件渲染的参数
72
74
  */