Skip to content

fix(Table): support set Fixed on column at runtime (#8094) - #8311

Open
h2ls wants to merge 4 commits into
mainfrom
lee/fix-table-dynamic-fixed-column
Open

fix(Table): support set Fixed on column at runtime (#8094)#8311
h2ls wants to merge 4 commits into
mainfrom
lee/fix-table-dynamic-fixed-column

Conversation

@h2ls

@h2ls h2ls commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator
  • 修复运行时动态设置列 Fixed 后固定列错位问题
  • colgroup 渲染时根据列当前 Fixed 状态回退默认固定列宽
  • GetLeftStyle 使用 DefaultFixedColumnWidth 替代硬编码 200
  • 运行时清空固定列边界缓存重新计算 fr/fl 样式
  • 脚本列宽自适应测量跳过固定列

close #8094

Link issues

fixes #{issue number}

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Improve runtime handling of fixed table columns to keep widths and offsets consistent when column fixed states change dynamically.

Bug Fixes:

  • Fix misaligned fixed columns when setting column Fixed at runtime by deriving colgroup widths from current fixed state and default fixed column width.
  • Ensure fixed column header and cell offsets use the configured DefaultFixedColumnWidth instead of a hardcoded value.
  • Clear cached fixed column boundary data when table parameters change so fixed column styles are recalculated correctly.
  • Prevent the script-based auto width measurement from modifying widths of fixed columns that are controlled by colgroup.

Tests:

  • Add a unit test covering dynamic toggling of column Fixed state and verifying colgroup widths and fixed column offsets update correctly.

- 修复运行时动态设置列 Fixed 后固定列错位问题
- colgroup 渲染时根据列当前 Fixed 状态回退默认固定列宽
- GetLeftStyle 使用 DefaultFixedColumnWidth 替代硬编码 200
- 运行时清空固定列边界缓存重新计算 fr/fl 样式
- 脚本列宽自适应测量跳过固定列

close #8094
@h2ls h2ls self-assigned this Aug 8, 2026
Copilot AI lite review requested due to automatic review settings August 8, 2026 05:31
@sourcery-ai

sourcery-ai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds 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 handling

sequenceDiagram
    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')
Loading

File-Level Changes

Change Details Files
Support dynamic runtime changes to column Fixed state and ensure colgroup widths and fixed-column offsets stay aligned.
  • Add a unit test that toggles column Fixed flags at runtime and verifies colgroup width, left-offset styles, and reset behavior after unfixing.
  • Use a helper to compute column width from TableColumnState, falling back to DefaultFixedColumnWidth when a fixed column has no explicit width.
  • Update colgroup rendering to use the new width helper so dynamically fixed columns get the default fixed width when necessary.
test/UnitTest/Components/TableTest.cs
src/BootstrapBlazor/Components/Table/Table.razor.cs
src/BootstrapBlazor/Components/Table/Table.razor
Maintain correct fixed-column boundary calculations when dynamic columns are used.
  • Clear FirstFixedColumnCache and LastFixedColumnCache whenever dynamic column mode is active, so fixed boundaries are recomputed after runtime changes.
src/BootstrapBlazor/Components/Table/Table.razor.cs
Align fixed-column offset calculation with the configurable default fixed column width.
  • Replace hard-coded width value 200 in GetLeftStyle with DefaultFixedColumnWidth to keep offsets consistent with colgroup widths and configuration.
src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs
Prevent JS auto-sizing from overriding widths of fixed columns.
  • Update setColSize in the JS interop to skip header cells marked as fixed so their widths remain controlled by colgroup.
src/BootstrapBlazor/Components/Table/Table.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#8094 Support dynamically changing the Fixed state of Table columns at runtime so that newly fixed/unfixed columns render correctly.
#8094 Ensure correct widths and left-offset styles for columns when Fixed is changed at runtime, including use of the default fixed column width and proper recalculation of fixed column boundaries.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto

bb-auto Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for your PR, @h2ls. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@bb-auto bb-auto Bot assigned ArgoZhang and unassigned h2ls Aug 8, 2026
@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 8, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fe9ce9f) to head (346a162).

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     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 colgroup widths based on the current runtime fixed state (with fallback to DefaultFixedColumnWidth for fixed columns lacking width in persisted state).
  • Replace a hardcoded fixed-column width (200) with DefaultFixedColumnWidth when 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.

Comment thread src/BootstrapBlazor/Components/Table/Table.razor.cs
h2ls and others added 3 commits August 8, 2026 14:43
- 修复自动生成列模式下每次渲染重建列实例导致运行时 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Table): 组件能否新增动态设置固定列的功能

4 participants