Skip to content

Conversation

@gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Dec 9, 2025

PR

修复columnIndex 错误问题

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Exposes a new reactive column marker on the table component for UI state tracking.
  • Refactor

    • Reworked column-list generation to build per-call column metadata and use per-entry columnIndex for lookups.
  • Bug Fixes

    • Fixed column index lookup to correctly preserve "not found" results and improve consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the bug Something isn't working label Dec 9, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 9, 2025

Walkthrough

Indexing and column-list construction were adjusted: getColumnIndex now reads the per-entry columnIndex from the column cache map; getColumnList gained a new first parameter ($table) and now records richer per-column metadata (including isLeaf and columnIndex); the table component exposes a new reactive markColumnIndex ref.

Changes

Cohort / File(s) Summary
Column index lookup change
packages/vue/src/grid/src/table/src/methods.ts
getColumnIndex() now returns the columnIndex property from the fullColumnMap entry (preserving -1 when not found) instead of the previous index lookup. watchColumn initializes this.markColumnIndex = 0 and calls getColumnList(this, value, options) (passing this as first arg).
Column list construction + caching
packages/renderless/src/grid/utils/common.ts
getColumnList signature changed to ($table, columns, options = {}, level = 0). The function now tracks isLeaf and pushes richer column cache entries ({ colid, column, index, isLeaf, columnIndex }) and passes $table recursively.
Component API addition
packages/vue/src/grid/src/table/src/table.ts
Added a reactive ref markColumnIndex (hooks.ref(0)) in setup and exposed it on the component public instance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to inspect:
    • All callers of getColumnList — update call sites to pass $table as the first argument.
    • The shape and lifecycle of the column cache entries: ensure columnIndex and isLeaf are computed and consumed consistently.
    • getColumnIndex change: verify consumers expect columnIndex semantics and that missing entries still yield -1.
    • Ensure markColumnIndex is properly initialized and intended public exposure does not leak internal state unexpectedly.

Poem

🐇 I hop through rows and columns bright,

I mark the index with soft delight,
I stash each leaf and track each line,
New caches hum — the grid's design,
A tiny twitch — the table's right.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(grid): fix columnIndex error' directly relates to the main changes in the PR, which fix the columnIndex lookup and computation logic in the grid module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cgm/fix-columnindex-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ccff4e and 083189e.

📒 Files selected for processing (3)
  • packages/renderless/src/grid/utils/common.ts (2 hunks)
  • packages/vue/src/grid/src/table/src/methods.ts (2 hunks)
  • packages/vue/src/grid/src/table/src/table.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/vue/src/grid/src/table/src/table.ts (1)
packages/vue-common/src/index.ts (1)
  • hooks (477-477)
packages/vue/src/grid/src/table/src/methods.ts (1)
packages/renderless/src/grid/utils/common.ts (1)
  • getColumnList (45-78)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (6)
packages/vue/src/grid/src/table/src/methods.ts (1)

998-1005: LGTM!

The initialization of markColumnIndex to 0 before calling getColumnList ensures fresh sequential indexing for each column rebuild. Passing this as the first parameter correctly provides the table instance context needed by the updated getColumnList signature.

packages/vue/src/grid/src/table/src/table.ts (2)

810-810: LGTM!

The reactive markColumnIndex counter is correctly initialized and will be used by getColumnList to assign sequential indexes to leaf columns during traversal.


845-846: LGTM!

Exposing markColumnIndex in the setup return allows methods (like watchColumn) to access and reset this counter as needed for column index tracking.

packages/renderless/src/grid/utils/common.ts (3)

65-72: LGTM!

The new logic correctly assigns sequential columnIndex values only to leaf columns (columns without children) using the $table.markColumnIndex counter. Non-leaf parent/group columns receive null, which is appropriate for hierarchical column structures.


74-74: LGTM!

The recursive call correctly passes $table as the first parameter, ensuring the markColumnIndex counter is shared across all levels of the column hierarchy.


45-45: All callers of getColumnList have been correctly updated.

The function signature change to add $table as the first parameter has been properly reflected in both call sites: the external call at line 1005 in packages/vue/src/grid/src/table/src/methods.ts and the recursive call at line 74 in packages/renderless/src/grid/utils/common.ts.

Comment on lines 579 to 583
getColumnIndex(column) {
const { fullColumnMap } = this

return fullColumnMap.has(column) ? fullColumnMap.get(column).index : -1
return fullColumnMap.has(column) ? fullColumnMap.get(column).columnIndex : -1
},
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.

@zzcr zzcr merged commit a0c2c73 into dev Dec 10, 2025
9 of 10 checks passed
@zzcr zzcr deleted the cgm/fix-columnindex-error branch December 10, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants