vxe-table 4.7.25 → 4.7.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vxe-table",
3
- "version": "4.7.25",
3
+ "version": "4.7.26",
4
4
  "description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、列拖拽,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
5
5
  "scripts": {
6
6
  "update": "npm install --legacy-peer-deps",
@@ -28,7 +28,7 @@
28
28
  "style": "lib/style.css",
29
29
  "typings": "types/index.d.ts",
30
30
  "dependencies": {
31
- "vxe-pc-ui": "^4.0.22"
31
+ "vxe-pc-ui": "^4.0.24"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/resize-observer-browser": "^0.1.11",
@@ -604,7 +604,7 @@ hooks.add('tableEditModule', {
604
604
  const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
605
605
  if (row && column && isEnableConf(editConfig) && isEnableConf(column.editRender)) {
606
606
  return $xeTable.scrollToRow(row, column).then(() => {
607
- const cell = $xeTable.getCell(row, column)
607
+ const cell = $xeTable.getCellElement(row, column)
608
608
  if (cell) {
609
609
  editPrivateMethods.handleActived({
610
610
  row,
@@ -631,7 +631,7 @@ hooks.add('tableEditModule', {
631
631
  if (row && column && editOpts.trigger !== 'manual') {
632
632
  const rowIndex = $xeTable.findRowIndexOf(tableData, row)
633
633
  if (rowIndex > -1 && column) {
634
- const cell = $xeTable.getCell(row, column)
634
+ const cell = $xeTable.getCellElement(row, column)
635
635
  const params = {
636
636
  row,
637
637
  rowIndex,
@@ -658,7 +658,7 @@ hooks.add('tableEditModule', {
658
658
  const { actived, focused } = editStore
659
659
  const { row, column } = params
660
660
  const { editRender } = column
661
- const cell = (params.cell || $xeTable.getCell(row, column))
661
+ const cell = (params.cell || $xeTable.getCellElement(row, column))
662
662
  const beforeEditMethod = editOpts.beforeEditMethod || editOpts.activeMethod
663
663
  params.cell = cell
664
664
  if (cell && isEnableConf(editConfig) && isEnableConf(editRender)) {
@@ -833,7 +833,7 @@ hooks.add('tableEditModule', {
833
833
  const { row, column } = selected
834
834
  removeCellSelectedClass()
835
835
  if (row && column) {
836
- const cell = $xeTable.getCell(row, column)
836
+ const cell = $xeTable.getCellElement(row, column)
837
837
  if (cell) {
838
838
  addClass(cell, 'col--selected')
839
839
  }
@@ -347,7 +347,7 @@ hooks.add('tableExportModule', {
347
347
  _expand: hasRowChild && $xeTable.isTreeExpandByRow(row)
348
348
  }
349
349
  columns.forEach((column, $columnIndex) => {
350
- let cellValue: string | boolean = ''
350
+ let cellValue: string | number | boolean = ''
351
351
  const renderOpts = column.editRender || column.cellRender
352
352
  let bodyExportMethod = column.exportMethod
353
353
  if (!bodyExportMethod && renderOpts && renderOpts.name) {
@@ -380,12 +380,12 @@ hooks.add('tableExportModule', {
380
380
  if (opts.original) {
381
381
  cellValue = getCellValue(row, column)
382
382
  } else {
383
- cellValue = $xeTable.getCellLabel(row, column)
383
+ cellValue = `${$xeTable.getCellLabel(row, column)}`
384
384
  if (column.type === 'html') {
385
385
  htmlCellElem.innerHTML = cellValue
386
386
  cellValue = htmlCellElem.innerText.trim()
387
387
  } else {
388
- const cell = $xeTable.getCell(row, column)
388
+ const cell = $xeTable.getCellElement(row, column)
389
389
  if (cell) {
390
390
  cellValue = cell.innerText.trim()
391
391
  }
@@ -406,7 +406,7 @@ hooks.add('tableExportModule', {
406
406
  _row: row
407
407
  }
408
408
  columns.forEach((column, $columnIndex) => {
409
- let cellValue: string | boolean = ''
409
+ let cellValue: string | number | boolean = ''
410
410
  const renderOpts = column.editRender || column.cellRender
411
411
  let exportLabelMethod = column.exportMethod
412
412
  if (!exportLabelMethod && renderOpts && renderOpts.name) {
@@ -436,12 +436,12 @@ hooks.add('tableExportModule', {
436
436
  if (opts.original) {
437
437
  cellValue = getCellValue(row, column)
438
438
  } else {
439
- cellValue = $xeTable.getCellLabel(row, column)
439
+ cellValue = `${$xeTable.getCellLabel(row, column)}`
440
440
  if (column.type === 'html') {
441
441
  htmlCellElem.innerHTML = cellValue
442
442
  cellValue = htmlCellElem.innerText.trim()
443
443
  } else {
444
- const cell = $xeTable.getCell(row, column)
444
+ const cell = $xeTable.getCellElement(row, column)
445
445
  if (cell) {
446
446
  cellValue = cell.innerText.trim()
447
447
  }
@@ -276,7 +276,7 @@ hooks.add('tableKeyboardModule', {
276
276
  }
277
277
  params.columnIndex = targetColumnIndex
278
278
  params.column = targetColumn
279
- params.cell = $xeTable.getCell(params.row, params.column)
279
+ params.cell = $xeTable.getCellElement(params.row, params.column)
280
280
  if (editConfig) {
281
281
  if (editOpts.trigger === 'click' || editOpts.trigger === 'dblclick') {
282
282
  if (editOpts.mode === 'row') {
@@ -356,7 +356,7 @@ hooks.add('tableKeyboardModule', {
356
356
  params.column = visibleColumn[params.columnIndex]
357
357
  }
358
358
  $xeTable.scrollToRow(params.row, params.column).then(() => {
359
- params.cell = $xeTable.getCell(params.row, params.column)
359
+ params.cell = $xeTable.getCellElement(params.row, params.column)
360
360
  $xeTable.handleSelected(params, evnt)
361
361
  })
362
362
  },
@@ -74,7 +74,7 @@ hooks.add('tableMenuModule', {
74
74
  const { keyboard, row, column } = params
75
75
  if (keyboard && row && column) {
76
76
  $xeTable.scrollToRow(row, column).then(() => {
77
- const cell = $xeTable.getCell(row, column)
77
+ const cell = $xeTable.getCellElement(row, column)
78
78
  if (cell) {
79
79
  const { boundingTop, boundingLeft } = getAbsolutePos(cell)
80
80
  top = boundingTop + scrollTop + Math.floor(cell.offsetHeight / 2)
@@ -215,7 +215,7 @@ hooks.add('tableValidatorModule', {
215
215
  })
216
216
  }
217
217
  const posAndFinish = () => {
218
- firstErrParams.cell = $xeTable.getCell(firstErrParams.row, firstErrParams.column)
218
+ firstErrParams.cell = $xeTable.getCellElement(firstErrParams.row, firstErrParams.column)
219
219
  scrollToView(firstErrParams.cell)
220
220
  handleValidError(firstErrParams).then(finish)
221
221
  }
@@ -1225,7 +1225,7 @@ export default defineComponent({
1225
1225
  if (sortBy) {
1226
1226
  cellValue = XEUtils.isFunction(sortBy) ? sortBy({ row, column }) : XEUtils.get(row, sortBy)
1227
1227
  } else {
1228
- cellValue = tablePrivateMethods.getCellLabel(row, column)
1228
+ cellValue = tableMethods.getCellLabel(row, column)
1229
1229
  }
1230
1230
  if (!sortType || sortType === 'auto') {
1231
1231
  return isNaN(cellValue) ? cellValue : XEUtils.toNumber(cellValue)
@@ -3050,6 +3050,80 @@ export default defineComponent({
3050
3050
  }
3051
3051
  return nextTick()
3052
3052
  },
3053
+ getCellElement (row, fieldOrColumn) {
3054
+ const column = handleFieldOrColumn($xeTable, fieldOrColumn)
3055
+ if (!column) {
3056
+ return null
3057
+ }
3058
+ const rowid = getRowid($xeTable, row)
3059
+ const tableBody = refTableBody.value
3060
+ const leftBody = refTableLeftBody.value
3061
+ const rightBody = refTableRightBody.value
3062
+ let bodyElem
3063
+ if (column) {
3064
+ if (column.fixed) {
3065
+ if (column.fixed === 'left') {
3066
+ if (leftBody) {
3067
+ bodyElem = leftBody.$el as HTMLDivElement
3068
+ }
3069
+ } else {
3070
+ if (rightBody) {
3071
+ bodyElem = rightBody.$el as HTMLDivElement
3072
+ }
3073
+ }
3074
+ }
3075
+ if (!bodyElem) {
3076
+ bodyElem = tableBody.$el as HTMLDivElement
3077
+ }
3078
+ if (bodyElem) {
3079
+ return bodyElem.querySelector(`.vxe-body--row[rowid="${rowid}"] .${column.id}`)
3080
+ }
3081
+ }
3082
+ return null
3083
+ },
3084
+ getCellLabel (row, fieldOrColumn) {
3085
+ const column = handleFieldOrColumn($xeTable, fieldOrColumn)
3086
+ if (!column) {
3087
+ return null
3088
+ }
3089
+ const formatter = column.formatter
3090
+ const cellValue = getCellValue(row, column)
3091
+ let cellLabel = cellValue
3092
+ if (formatter) {
3093
+ let formatData
3094
+ const { fullAllDataRowIdData } = internalData
3095
+ const rowid = getRowid($xeTable, row)
3096
+ const colid = column.id
3097
+ const rest = fullAllDataRowIdData[rowid]
3098
+ if (rest) {
3099
+ formatData = rest.formatData
3100
+ if (!formatData) {
3101
+ formatData = fullAllDataRowIdData[rowid].formatData = {}
3102
+ }
3103
+ if (rest && formatData[colid]) {
3104
+ if (formatData[colid].value === cellValue) {
3105
+ return formatData[colid].label
3106
+ }
3107
+ }
3108
+ }
3109
+ const formatParams = { cellValue, row, rowIndex: tableMethods.getRowIndex(row), column, columnIndex: tableMethods.getColumnIndex(column) }
3110
+ if (XEUtils.isString(formatter)) {
3111
+ const gFormatOpts = formats.get(formatter)
3112
+ const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
3113
+ cellLabel = tcFormatMethod ? tcFormatMethod(formatParams) : ''
3114
+ } else if (XEUtils.isArray(formatter)) {
3115
+ const gFormatOpts = formats.get(formatter[0])
3116
+ const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
3117
+ cellLabel = tcFormatMethod ? tcFormatMethod(formatParams, ...formatter.slice(1)) : ''
3118
+ } else {
3119
+ cellLabel = formatter(formatParams)
3120
+ }
3121
+ if (formatData) {
3122
+ formatData[colid] = { value: cellValue, label: cellLabel }
3123
+ }
3124
+ }
3125
+ return cellLabel
3126
+ },
3053
3127
  /**
3054
3128
  * 检查是否为临时行数据
3055
3129
  * @param {Row} row 行对象
@@ -3105,6 +3179,13 @@ export default defineComponent({
3105
3179
  const columns = internalData.visibleColumn
3106
3180
  return XEUtils.isUndefined(columnIndex) ? columns.slice(0) : columns[columnIndex]
3107
3181
  },
3182
+ /**
3183
+ * 根据列获取列的唯一主键
3184
+ */
3185
+ getColid (fieldOrColumn) {
3186
+ const column = handleFieldOrColumn($xeTable, fieldOrColumn)
3187
+ return column ? column.id : null
3188
+ },
3108
3189
  /**
3109
3190
  * 根据列的唯一主键获取列
3110
3191
  * @param {String} colid 列主键
@@ -4378,7 +4459,7 @@ export default defineComponent({
4378
4459
  const type = 'change'
4379
4460
  if ($xeTable.hasCellRules) {
4380
4461
  if ($xeTable.hasCellRules(type, row, column)) {
4381
- const cell = tablePrivateMethods.getCell(row, column)
4462
+ const cell = tableMethods.getCellElement(row, column)
4382
4463
  if (cell) {
4383
4464
  return $xeTable.validCellRules(type, row, column, cellValue)
4384
4465
  .then(() => {
@@ -6245,71 +6326,12 @@ export default defineComponent({
6245
6326
  }
6246
6327
  internalData.hoverRow = null
6247
6328
  },
6329
+ /**
6330
+ * 已废弃,被 getCellElement 替换
6331
+ * @deprecated
6332
+ */
6248
6333
  getCell (row, column) {
6249
- const rowid = getRowid($xeTable, row)
6250
- const tableBody = refTableBody.value
6251
- const leftBody = refTableLeftBody.value
6252
- const rightBody = refTableRightBody.value
6253
- let bodyElem
6254
- if (column) {
6255
- if (column.fixed) {
6256
- if (column.fixed === 'left') {
6257
- if (leftBody) {
6258
- bodyElem = leftBody.$el as HTMLDivElement
6259
- }
6260
- } else {
6261
- if (rightBody) {
6262
- bodyElem = rightBody.$el as HTMLDivElement
6263
- }
6264
- }
6265
- }
6266
- if (!bodyElem) {
6267
- bodyElem = tableBody.$el as HTMLDivElement
6268
- }
6269
- if (bodyElem) {
6270
- return bodyElem.querySelector(`.vxe-body--row[rowid="${rowid}"] .${column.id}`)
6271
- }
6272
- }
6273
- return null
6274
- },
6275
- getCellLabel (row, column) {
6276
- const formatter = column.formatter
6277
- const cellValue = getCellValue(row, column)
6278
- let cellLabel = cellValue
6279
- if (formatter) {
6280
- let formatData
6281
- const { fullAllDataRowIdData } = internalData
6282
- const rowid = getRowid($xeTable, row)
6283
- const colid = column.id
6284
- const rest = fullAllDataRowIdData[rowid]
6285
- if (rest) {
6286
- formatData = rest.formatData
6287
- if (!formatData) {
6288
- formatData = fullAllDataRowIdData[rowid].formatData = {}
6289
- }
6290
- if (rest && formatData[colid]) {
6291
- if (formatData[colid].value === cellValue) {
6292
- return formatData[colid].label
6293
- }
6294
- }
6295
- }
6296
- const formatParams = { cellValue, row, rowIndex: tableMethods.getRowIndex(row), column, columnIndex: tableMethods.getColumnIndex(column) }
6297
- if (XEUtils.isString(formatter)) {
6298
- const gFormatOpts = formats.get(formatter)
6299
- const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
6300
- cellLabel = tcFormatMethod ? tcFormatMethod(formatParams) : ''
6301
- } else if (XEUtils.isArray(formatter)) {
6302
- const gFormatOpts = formats.get(formatter[0])
6303
- const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
6304
- cellLabel = tcFormatMethod ? tcFormatMethod(formatParams, ...formatter.slice(1)) : ''
6305
- } else {
6306
- cellLabel = formatter(formatParams)
6307
- }
6308
- if (formatData) {
6309
- formatData[colid] = { value: cellValue, label: cellLabel }
6310
- }
6311
- }
6312
- return cellLabel
6334
+ return tableMethods.getCellElement(row, column)
6313
6335
  },
6314
6336
  findRowIndexOf (list, row) {
6315
6337
  return row ? XEUtils.findIndexOf(list, item => $xeTable.eqRow(item, row)) : -1