Skip to content

Commit a0c2c73

Browse files
authored
fix(grid): fix columnIndex error (#3890)
* fix(grid): fix columnIndex error * fix(grid): fix columnIndex error
1 parent 6922ff2 commit a0c2c73

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/renderless/src/grid/utils/common.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const getRowid = ($table, row) => {
4242
}
4343

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

4848
columns.forEach((column, index) => {
@@ -62,10 +62,16 @@ export const getColumnList = (columns, options = {}, level = 0) => {
6262
if (level === 0 && !options.isGroup && hasChildren) {
6363
options.isGroup = true
6464
}
65+
const isLeaf = !hasChildren
66+
options.columnCaches.push({
67+
colid: column.id,
68+
column,
69+
index,
70+
isLeaf,
71+
columnIndex: isLeaf ? $table.markColumnIndex++ : null
72+
})
6573

66-
options.columnCaches.push({ colid: column.id, column, index })
67-
68-
result.push.apply(result, hasChildren ? getColumnList(column.children, options, level + 1) : [column])
74+
result.push.apply(result, hasChildren ? getColumnList($table, column.children, options, level + 1) : [column])
6975
})
7076

7177
return result

packages/vue/src/grid/src/table/src/methods.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ const Methods = {
579579
getColumnIndex(column) {
580580
const { fullColumnMap } = this
581581

582-
return fullColumnMap.has(column) ? fullColumnMap.get(column).index : -1
582+
return fullColumnMap.has(column) ? fullColumnMap.get(column).columnIndex : -1
583583
},
584584
hasIndexColumn(column) {
585585
return column?.type === 'index'
@@ -1001,7 +1001,8 @@ const Methods = {
10011001

10021002
// 获取叶子列数组
10031003
const options = { columnCaches: [] }
1004-
const fullColumn = getColumnList(value, options)
1004+
this.markColumnIndex = 0
1005+
const fullColumn = getColumnList(this, value, options)
10051006

10061007
if (options.isGroup && options.hasFixed) {
10071008
value.forEach((root) => repairFixed(root))

packages/vue/src/grid/src/table/src/table.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ export default defineComponent({
807807

808808
const tableListeners = getListeners(attrs, listeners)
809809

810+
const markColumnIndex = hooks.ref(0)
810811
return {
811812
slots,
812813
tableListeners,
@@ -841,7 +842,8 @@ export default defineComponent({
841842
columnStore,
842843
tiledLength,
843844
rawDataVersion,
844-
rawData
845+
rawData,
846+
markColumnIndex
845847
}
846848
},
847849
render() {

0 commit comments

Comments
 (0)