Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/renderless/src/grid/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const getRowid = ($table, row) => {
}

// 获取所有的列,排除分组
export const getColumnList = (columns, options = {}, level = 0) => {
export const getColumnList = ($table, columns, options = {}, level = 0) => {
const result = []

columns.forEach((column, index) => {
Expand All @@ -62,10 +62,16 @@ export const getColumnList = (columns, options = {}, level = 0) => {
if (level === 0 && !options.isGroup && hasChildren) {
options.isGroup = true
}
const isLeaf = !hasChildren
options.columnCaches.push({
colid: column.id,
column,
index,
isLeaf,
columnIndex: isLeaf ? $table.markColumnIndex++ : null
})

options.columnCaches.push({ colid: column.id, column, index })

result.push.apply(result, hasChildren ? getColumnList(column.children, options, level + 1) : [column])
result.push.apply(result, hasChildren ? getColumnList($table, column.children, options, level + 1) : [column])
})

return result
Expand Down
5 changes: 3 additions & 2 deletions packages/vue/src/grid/src/table/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ const Methods = {
getColumnIndex(column) {
const { fullColumnMap } = this

return fullColumnMap.has(column) ? fullColumnMap.get(column).index : -1
return fullColumnMap.has(column) ? fullColumnMap.get(column).columnIndex : -1
},
Comment on lines 579 to 583
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Verify handling of non-leaf column indexes.

The new implementation returns columnIndex from the cached map entry, which will be null for non-leaf (parent/group) columns. This differs from the fallback -1 for columns not found in the map, potentially leading to inconsistent return types (null vs -1).

Consider normalizing the return value:

 getColumnIndex(column) {
   const { fullColumnMap } = this

-  return fullColumnMap.has(column) ? fullColumnMap.get(column).columnIndex : -1
+  return fullColumnMap.has(column) ? (fullColumnMap.get(column).columnIndex ?? -1) : -1
 },
🤖 Prompt for AI Agents
In packages/vue/src/grid/src/table/src/methods.ts around lines 579 to 583, the
method returns fullColumnMap.get(column).columnIndex which can be null for
non-leaf (group) columns, causing inconsistent return types (null vs -1); change
the logic to normalize the result to a number by returning the stored
columnIndex when it is a valid number and returning -1 when the map has no entry
or when columnIndex is null/undefined so the method always returns -1 for
non-leaf or missing columns.

hasIndexColumn(column) {
return column?.type === 'index'
Expand Down Expand Up @@ -1001,7 +1001,8 @@ const Methods = {

// 获取叶子列数组
const options = { columnCaches: [] }
const fullColumn = getColumnList(value, options)
this.markColumnIndex = 0
const fullColumn = getColumnList(this, value, options)

if (options.isGroup && options.hasFixed) {
value.forEach((root) => repairFixed(root))
Expand Down
4 changes: 3 additions & 1 deletion packages/vue/src/grid/src/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ export default defineComponent({

const tableListeners = getListeners(attrs, listeners)

const markColumnIndex = hooks.ref(0)
return {
slots,
tableListeners,
Expand Down Expand Up @@ -841,7 +842,8 @@ export default defineComponent({
columnStore,
tiledLength,
rawDataVersion,
rawData
rawData,
markColumnIndex
}
},
render() {
Expand Down
Loading