Skip to content

fix(grid): fix bug after refactor #3527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/theme-saas/src/grid/table.less
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@
@apply flex-auto;
@apply items-center;
@apply justify-center;
@apply text-center;
@apply sticky;
@apply left-0;
}
Expand Down
1 change: 1 addition & 0 deletions packages/theme/src/grid/table.less
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
display: flex;
align-items: center;
justify-content: center;
text-align: center;
position: sticky;
left: 0;
flex: auto;
Expand Down
9 changes: 6 additions & 3 deletions packages/vue/src/grid/src/keyboard/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,13 @@ export default {
this.editStore.indexs.rowNodes = rowNodes
},
_clearIndexChecked() {
let indexCheckeds = this.elemStore['main-body-list'].querySelectorAll('.col__index-checked')
let eachHandler = (colNode) => removeClass(colNode, 'col__index-checked')
const tbody = this.elemStore['main-body-list']
if (tbody) {
const indexCheckeds = tbody.querySelectorAll('.col__index-checked')
const eachHandler = (colNode) => removeClass(colNode, 'col__index-checked')

arrayEach(indexCheckeds, eachHandler)
arrayEach(indexCheckeds, eachHandler)
}

Object.assign(this.editStore.indexs, { rowNodes: [] })

Expand Down
16 changes: 8 additions & 8 deletions packages/vue/src/grid/src/table/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,15 @@ const Methods = {
}
},
// 更新列的 Map
cacheColumnMap() {
let { fullColumnMap, tableFullColumn: fullColumn } = this
let fullColumnIdData = {}
cacheColumnMap(options) {
const { fullColumnMap } = this
const fullColumnIdData = {}
this.fullColumnIdData = fullColumnIdData
Map.prototype.clear.apply(fullColumnMap)
fullColumn.forEach((column, index) => {
let colCache = { colid: column.id, column, index }
fullColumnIdData[column.id] = colCache
fullColumnMap.set(column, colCache)
fullColumnMap.clear()

options.columnCaches.forEach((cache) => {
fullColumnIdData[cache.colid] = cache
fullColumnMap.set(cache.column, cache)
})
},
Comment on lines +410 to 420
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add input validation and error handling for robustness.

The method now accepts external cache data but lacks proper validation, which could cause runtime errors if options or options.columnCaches is undefined or malformed.

Apply this diff to add proper input validation:

-  cacheColumnMap(options) {
+  cacheColumnMap(options) {
+    if (!options || !Array.isArray(options.columnCaches)) {
+      throw new Error('cacheColumnMap requires options.columnCaches to be an array')
+    }
+    
     const { fullColumnMap } = this
     const fullColumnIdData = {}
     this.fullColumnIdData = fullColumnIdData
     fullColumnMap.clear()

     options.columnCaches.forEach((cache) => {
+      if (!cache || !cache.colid || !cache.column) {
+        throw new Error('Invalid cache object: must have colid and column properties')
+      }
       fullColumnIdData[cache.colid] = cache
       fullColumnMap.set(cache.column, cache)
     })
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cacheColumnMap(options) {
const { fullColumnMap } = this
const fullColumnIdData = {}
this.fullColumnIdData = fullColumnIdData
Map.prototype.clear.apply(fullColumnMap)
fullColumn.forEach((column, index) => {
let colCache = { colid: column.id, column, index }
fullColumnIdData[column.id] = colCache
fullColumnMap.set(column, colCache)
fullColumnMap.clear()
options.columnCaches.forEach((cache) => {
fullColumnIdData[cache.colid] = cache
fullColumnMap.set(cache.column, cache)
})
},
cacheColumnMap(options) {
if (!options || !Array.isArray(options.columnCaches)) {
throw new Error('cacheColumnMap requires options.columnCaches to be an array')
}
const { fullColumnMap } = this
const fullColumnIdData = {}
this.fullColumnIdData = fullColumnIdData
fullColumnMap.clear()
options.columnCaches.forEach((cache) => {
if (!cache || !cache.colid || !cache.column) {
throw new Error('Invalid cache object: must have colid and column properties')
}
fullColumnIdData[cache.colid] = cache
fullColumnMap.set(cache.column, cache)
})
},
🤖 Prompt for AI Agents
In packages/vue/src/grid/src/table/src/methods.ts around lines 410 to 420, the
cacheColumnMap method lacks validation for the options parameter and its
columnCaches property, which may cause runtime errors if they are undefined or
malformed. Add checks to verify that options is an object and
options.columnCaches is an array before proceeding. If validation fails, handle
the error gracefully, for example by returning early or logging a warning, to
ensure robustness.

// 通过tr的dom元素获取行数据等相关信息
Expand Down
Loading