fix(Table): support set Fixed on column at runtime (#8094) - #8311
Conversation
- 修复运行时动态设置列 Fixed 后固定列错位问题 - colgroup 渲染时根据列当前 Fixed 状态回退默认固定列宽 - GetLeftStyle 使用 DefaultFixedColumnWidth 替代硬编码 200 - 运行时清空固定列边界缓存重新计算 fr/fl 样式 - 脚本列宽自适应测量跳过固定列 close #8094
Reviewer's GuideAdds runtime support for dynamically fixing/unfixing table columns while keeping colgroup widths and fixed-column offsets consistent, introduces a default fixed-column width for both rendering and style calculations, clears cached fixed-column boundaries when dynamic columns are used, and ensures JS auto-sizing skips fixed columns. Includes a unit test covering the dynamic fixed-column behavior end-to-end. Sequence diagram for runtime fixed column update handlingsequenceDiagram
title Runtime fixed column update handling
actor User
participant Table
participant Razor
participant Browser
participant Js
User->>Table: change column.Fixed at runtime
Table->>Table: OnParametersSet()
Table->>Table: ResetDynamicContext()
Table->>Table: FirstFixedColumnCache.Clear()
Table->>Table: LastFixedColumnCache.Clear()
Table->>Razor: GetColWidth(state)
Razor->>Browser: render colgroup with GetColWidthString()
Browser->>Js: setColSize(table, options)
Js->>Js: skip fixed columns with classList.contains('fixed')
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Thanks for your PR, @h2ls. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- GetColWidth currently does a Columns.Find lookup per state during colgroup rendering, which may be called frequently; consider avoiding repeated linear searches (e.g., by caching a name→column map) if the column count can be large.
- The cache clearing logic for FirstFixedColumnCache and LastFixedColumnCache is only triggered in dynamic column mode; if columns can toggle Fixed at runtime in non-dynamic scenarios, you may need similar cache invalidation there to keep fixed boundaries in sync.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- GetColWidth currently does a Columns.Find lookup per state during colgroup rendering, which may be called frequently; consider avoiding repeated linear searches (e.g., by caching a name→column map) if the column count can be large.
- The cache clearing logic for FirstFixedColumnCache and LastFixedColumnCache is only triggered in dynamic column mode; if columns can toggle Fixed at runtime in non-dynamic scenarios, you may need similar cache invalidation there to keep fixed boundaries in sync.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8311 +/- ##
========================================
Coverage 99.99% 100.00%
========================================
Files 771 771
Lines 34535 34562 +27
========================================
+ Hits 34532 34562 +30
+ Misses 3 0 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes misalignment issues when toggling TableColumn.Fixed at runtime in the BootstrapBlazor Table component by ensuring fixed-column widths and offsets are derived consistently from the current fixed state and configured default fixed width.
Changes:
- Render
colgroupwidths based on the current runtime fixed state (with fallback toDefaultFixedColumnWidthfor fixed columns lacking width in persisted state). - Replace a hardcoded fixed-column width (200) with
DefaultFixedColumnWidthwhen computing fixed column offsets. - Recompute fixed-column boundary state when parameters are set, and prevent script auto-width measurement from altering fixed columns.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTest/Components/TableTest.cs | Adds a unit test validating dynamic toggling of column Fixed updates colgroup widths and left offsets. |
| src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs | Uses DefaultFixedColumnWidth when calculating fixed column left offsets. |
| src/BootstrapBlazor/Components/Table/Table.razor.js | Skips script-based auto width measurement for fixed columns (colgroup-controlled). |
| src/BootstrapBlazor/Components/Table/Table.razor.cs | Adds runtime fallback width logic for colgroup and clears fixed-column boundary caches on parameter set. |
| src/BootstrapBlazor/Components/Table/Table.razor | Switches colgroup rendering to use the new width resolution method. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- 修复自动生成列模式下每次渲染重建列实例导致运行时 Fixed 变更丢失的问题 - 列重建前缓存运行时固定列状态,重建后按字段名回放 - 固定列边界缓存移至 ResetTableColumns 清理,避免按引用累积过期列实例 - 补充自动生成列模式下动态切换固定列的单元测试
- 自动布局下列实际渲染宽度可能大于声明宽度,导致 sticky 偏移错位滚动覆盖 - 固定列集合变化时通知客户端脚本按实测宽度重算偏移 - 增加 ResizeObserver 跟踪数据加载/翻页/尺寸变化后的布局漂移
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: LEE <33386249+h2ls@users.noreply.github.com>
close #8094
Link issues
fixes #{issue number}
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Improve runtime handling of fixed table columns to keep widths and offsets consistent when column fixed states change dynamically.
Bug Fixes:
Tests: