Skip to content

Commit

Permalink
releases 4.7.26
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jun 20, 2024
1 parent efd8957 commit 85dd0cf
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 82 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table",
"version": "4.7.25",
"version": "4.7.26",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、列拖拽,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down Expand Up @@ -28,7 +28,7 @@
"style": "lib/style.css",
"typings": "types/index.d.ts",
"dependencies": {
"vxe-pc-ui": "^4.0.22"
"vxe-pc-ui": "^4.0.24"
},
"devDependencies": {
"@types/resize-observer-browser": "^0.1.11",
Expand Down
8 changes: 4 additions & 4 deletions packages/table/module/edit/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ hooks.add('tableEditModule', {
const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
if (row && column && isEnableConf(editConfig) && isEnableConf(column.editRender)) {
return $xeTable.scrollToRow(row, column).then(() => {
const cell = $xeTable.getCell(row, column)
const cell = $xeTable.getCellElement(row, column)
if (cell) {
editPrivateMethods.handleActived({
row,
Expand All @@ -631,7 +631,7 @@ hooks.add('tableEditModule', {
if (row && column && editOpts.trigger !== 'manual') {
const rowIndex = $xeTable.findRowIndexOf(tableData, row)
if (rowIndex > -1 && column) {
const cell = $xeTable.getCell(row, column)
const cell = $xeTable.getCellElement(row, column)
const params = {
row,
rowIndex,
Expand All @@ -658,7 +658,7 @@ hooks.add('tableEditModule', {
const { actived, focused } = editStore
const { row, column } = params
const { editRender } = column
const cell = (params.cell || $xeTable.getCell(row, column))
const cell = (params.cell || $xeTable.getCellElement(row, column))
const beforeEditMethod = editOpts.beforeEditMethod || editOpts.activeMethod
params.cell = cell
if (cell && isEnableConf(editConfig) && isEnableConf(editRender)) {
Expand Down Expand Up @@ -833,7 +833,7 @@ hooks.add('tableEditModule', {
const { row, column } = selected
removeCellSelectedClass()
if (row && column) {
const cell = $xeTable.getCell(row, column)
const cell = $xeTable.getCellElement(row, column)
if (cell) {
addClass(cell, 'col--selected')
}
Expand Down
12 changes: 6 additions & 6 deletions packages/table/module/export/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ hooks.add('tableExportModule', {
_expand: hasRowChild && $xeTable.isTreeExpandByRow(row)
}
columns.forEach((column, $columnIndex) => {
let cellValue: string | boolean = ''
let cellValue: string | number | boolean = ''
const renderOpts = column.editRender || column.cellRender
let bodyExportMethod = column.exportMethod
if (!bodyExportMethod && renderOpts && renderOpts.name) {
Expand Down Expand Up @@ -380,12 +380,12 @@ hooks.add('tableExportModule', {
if (opts.original) {
cellValue = getCellValue(row, column)
} else {
cellValue = $xeTable.getCellLabel(row, column)
cellValue = `${$xeTable.getCellLabel(row, column)}`
if (column.type === 'html') {
htmlCellElem.innerHTML = cellValue
cellValue = htmlCellElem.innerText.trim()
} else {
const cell = $xeTable.getCell(row, column)
const cell = $xeTable.getCellElement(row, column)
if (cell) {
cellValue = cell.innerText.trim()
}
Expand All @@ -406,7 +406,7 @@ hooks.add('tableExportModule', {
_row: row
}
columns.forEach((column, $columnIndex) => {
let cellValue: string | boolean = ''
let cellValue: string | number | boolean = ''
const renderOpts = column.editRender || column.cellRender
let exportLabelMethod = column.exportMethod
if (!exportLabelMethod && renderOpts && renderOpts.name) {
Expand Down Expand Up @@ -436,12 +436,12 @@ hooks.add('tableExportModule', {
if (opts.original) {
cellValue = getCellValue(row, column)
} else {
cellValue = $xeTable.getCellLabel(row, column)
cellValue = `${$xeTable.getCellLabel(row, column)}`
if (column.type === 'html') {
htmlCellElem.innerHTML = cellValue
cellValue = htmlCellElem.innerText.trim()
} else {
const cell = $xeTable.getCell(row, column)
const cell = $xeTable.getCellElement(row, column)
if (cell) {
cellValue = cell.innerText.trim()
}
Expand Down
4 changes: 2 additions & 2 deletions packages/table/module/keyboard/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ hooks.add('tableKeyboardModule', {
}
params.columnIndex = targetColumnIndex
params.column = targetColumn
params.cell = $xeTable.getCell(params.row, params.column)
params.cell = $xeTable.getCellElement(params.row, params.column)
if (editConfig) {
if (editOpts.trigger === 'click' || editOpts.trigger === 'dblclick') {
if (editOpts.mode === 'row') {
Expand Down Expand Up @@ -356,7 +356,7 @@ hooks.add('tableKeyboardModule', {
params.column = visibleColumn[params.columnIndex]
}
$xeTable.scrollToRow(params.row, params.column).then(() => {
params.cell = $xeTable.getCell(params.row, params.column)
params.cell = $xeTable.getCellElement(params.row, params.column)
$xeTable.handleSelected(params, evnt)
})
},
Expand Down
2 changes: 1 addition & 1 deletion packages/table/module/menu/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ hooks.add('tableMenuModule', {
const { keyboard, row, column } = params
if (keyboard && row && column) {
$xeTable.scrollToRow(row, column).then(() => {
const cell = $xeTable.getCell(row, column)
const cell = $xeTable.getCellElement(row, column)
if (cell) {
const { boundingTop, boundingLeft } = getAbsolutePos(cell)
top = boundingTop + scrollTop + Math.floor(cell.offsetHeight / 2)
Expand Down
2 changes: 1 addition & 1 deletion packages/table/module/validator/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ hooks.add('tableValidatorModule', {
})
}
const posAndFinish = () => {
firstErrParams.cell = $xeTable.getCell(firstErrParams.row, firstErrParams.column)
firstErrParams.cell = $xeTable.getCellElement(firstErrParams.row, firstErrParams.column)
scrollToView(firstErrParams.cell)
handleValidError(firstErrParams).then(finish)
}
Expand Down
154 changes: 88 additions & 66 deletions packages/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ export default defineComponent({
if (sortBy) {
cellValue = XEUtils.isFunction(sortBy) ? sortBy({ row, column }) : XEUtils.get(row, sortBy)
} else {
cellValue = tablePrivateMethods.getCellLabel(row, column)
cellValue = tableMethods.getCellLabel(row, column)
}
if (!sortType || sortType === 'auto') {
return isNaN(cellValue) ? cellValue : XEUtils.toNumber(cellValue)
Expand Down Expand Up @@ -3050,6 +3050,80 @@ export default defineComponent({
}
return nextTick()
},
getCellElement (row, fieldOrColumn) {
const column = handleFieldOrColumn($xeTable, fieldOrColumn)
if (!column) {
return null
}
const rowid = getRowid($xeTable, row)
const tableBody = refTableBody.value
const leftBody = refTableLeftBody.value
const rightBody = refTableRightBody.value
let bodyElem
if (column) {
if (column.fixed) {
if (column.fixed === 'left') {
if (leftBody) {
bodyElem = leftBody.$el as HTMLDivElement
}
} else {
if (rightBody) {
bodyElem = rightBody.$el as HTMLDivElement
}
}
}
if (!bodyElem) {
bodyElem = tableBody.$el as HTMLDivElement
}
if (bodyElem) {
return bodyElem.querySelector(`.vxe-body--row[rowid="${rowid}"] .${column.id}`)
}
}
return null
},
getCellLabel (row, fieldOrColumn) {
const column = handleFieldOrColumn($xeTable, fieldOrColumn)
if (!column) {
return null
}
const formatter = column.formatter
const cellValue = getCellValue(row, column)
let cellLabel = cellValue
if (formatter) {
let formatData
const { fullAllDataRowIdData } = internalData
const rowid = getRowid($xeTable, row)
const colid = column.id
const rest = fullAllDataRowIdData[rowid]
if (rest) {
formatData = rest.formatData
if (!formatData) {
formatData = fullAllDataRowIdData[rowid].formatData = {}
}
if (rest && formatData[colid]) {
if (formatData[colid].value === cellValue) {
return formatData[colid].label
}
}
}
const formatParams = { cellValue, row, rowIndex: tableMethods.getRowIndex(row), column, columnIndex: tableMethods.getColumnIndex(column) }
if (XEUtils.isString(formatter)) {
const gFormatOpts = formats.get(formatter)
const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
cellLabel = tcFormatMethod ? tcFormatMethod(formatParams) : ''
} else if (XEUtils.isArray(formatter)) {
const gFormatOpts = formats.get(formatter[0])
const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
cellLabel = tcFormatMethod ? tcFormatMethod(formatParams, ...formatter.slice(1)) : ''
} else {
cellLabel = formatter(formatParams)
}
if (formatData) {
formatData[colid] = { value: cellValue, label: cellLabel }
}
}
return cellLabel
},
/**
* 检查是否为临时行数据
* @param {Row} row 行对象
Expand Down Expand Up @@ -3105,6 +3179,13 @@ export default defineComponent({
const columns = internalData.visibleColumn
return XEUtils.isUndefined(columnIndex) ? columns.slice(0) : columns[columnIndex]
},
/**
* 根据列获取列的唯一主键
*/
getColid (fieldOrColumn) {
const column = handleFieldOrColumn($xeTable, fieldOrColumn)
return column ? column.id : null
},
/**
* 根据列的唯一主键获取列
* @param {String} colid 列主键
Expand Down Expand Up @@ -4378,7 +4459,7 @@ export default defineComponent({
const type = 'change'
if ($xeTable.hasCellRules) {
if ($xeTable.hasCellRules(type, row, column)) {
const cell = tablePrivateMethods.getCell(row, column)
const cell = tableMethods.getCellElement(row, column)
if (cell) {
return $xeTable.validCellRules(type, row, column, cellValue)
.then(() => {
Expand Down Expand Up @@ -6245,71 +6326,12 @@ export default defineComponent({
}
internalData.hoverRow = null
},
/**
* 已废弃,被 getCellElement 替换
* @deprecated
*/
getCell (row, column) {
const rowid = getRowid($xeTable, row)
const tableBody = refTableBody.value
const leftBody = refTableLeftBody.value
const rightBody = refTableRightBody.value
let bodyElem
if (column) {
if (column.fixed) {
if (column.fixed === 'left') {
if (leftBody) {
bodyElem = leftBody.$el as HTMLDivElement
}
} else {
if (rightBody) {
bodyElem = rightBody.$el as HTMLDivElement
}
}
}
if (!bodyElem) {
bodyElem = tableBody.$el as HTMLDivElement
}
if (bodyElem) {
return bodyElem.querySelector(`.vxe-body--row[rowid="${rowid}"] .${column.id}`)
}
}
return null
},
getCellLabel (row, column) {
const formatter = column.formatter
const cellValue = getCellValue(row, column)
let cellLabel = cellValue
if (formatter) {
let formatData
const { fullAllDataRowIdData } = internalData
const rowid = getRowid($xeTable, row)
const colid = column.id
const rest = fullAllDataRowIdData[rowid]
if (rest) {
formatData = rest.formatData
if (!formatData) {
formatData = fullAllDataRowIdData[rowid].formatData = {}
}
if (rest && formatData[colid]) {
if (formatData[colid].value === cellValue) {
return formatData[colid].label
}
}
}
const formatParams = { cellValue, row, rowIndex: tableMethods.getRowIndex(row), column, columnIndex: tableMethods.getColumnIndex(column) }
if (XEUtils.isString(formatter)) {
const gFormatOpts = formats.get(formatter)
const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
cellLabel = tcFormatMethod ? tcFormatMethod(formatParams) : ''
} else if (XEUtils.isArray(formatter)) {
const gFormatOpts = formats.get(formatter[0])
const tcFormatMethod = gFormatOpts ? (gFormatOpts.tableCellFormatMethod || gFormatOpts.cellFormatMethod) : null
cellLabel = tcFormatMethod ? tcFormatMethod(formatParams, ...formatter.slice(1)) : ''
} else {
cellLabel = formatter(formatParams)
}
if (formatData) {
formatData[colid] = { value: cellValue, label: cellLabel }
}
}
return cellLabel
return tableMethods.getCellElement(row, column)
},
findRowIndexOf (list, row) {
return row ? XEUtils.findIndexOf(list, item => $xeTable.eqRow(item, row)) : -1
Expand Down

0 comments on commit 85dd0cf

Please sign in to comment.