Skip to content

doc(Table): update ClearTableColumnClientStatus sample code#8007

Merged
ArgoZhang merged 11 commits into
mainfrom
refactor-table
May 17, 2026
Merged

doc(Table): update ClearTableColumnClientStatus sample code#8007
ArgoZhang merged 11 commits into
mainfrom
refactor-table

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 17, 2026

Link issues

fixes #8006

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

Adjust table column width persistence and sample usage for client-side column state clearing and resizing.

Bug Fixes:

  • Ensure column width updates are reflected via DOM colgroup markup rather than relying on server-side column width properties.
  • Align JavaScript auto-fit behavior to reuse the resize column callback when persisting and reporting column width changes.

Enhancements:

  • Simplify and centralize table column width handling by using cached column state for rendering and removing fixed-width extension helpers.
  • Update ClearTableColumnClientStatus behavior to rely on state refresh instead of internal reset flags when clearing cached column states.
  • Refine table column drag sample to demonstrate clearing client column status via a toolbar reset button and improved localized description text.

Documentation:

  • Add localized documentation strings describing clearing table column client status in the column drag sample.

Tests:

  • Update and extend table column client status unit tests to validate rendered column widths and header-inclusive resizing behavior while removing obsolete auto-fit callback coverage.

Copilot AI review requested due to automatic review settings May 17, 2026 07:18
@bb-auto bb-auto Bot added the enhancement New feature or request label May 17, 2026
@bb-auto bb-auto Bot added this to the v10.6.0 milestone May 17, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 17, 2026

Reviewer's Guide

Updates the table column client status persistence and demo to use the unified resize callback and column state list, adjusts how column widths are rendered and reset, and adds a reset sample for clearing client-side column settings while updating tests accordingly.

Sequence diagram for unified column resize callback and reset behavior

sequenceDiagram
    actor User
    participant TablesColumnDrag as TablesColumnDrag
    participant Table as Table_Foo_
    participant BrowserJs as Table_razor_js
    participant AppHandler as OnTableColumnClientStatusChanged

    rect rgb(230,230,250)
    User->>BrowserJs: autoFitColumnWidth(table, col)
    BrowserJs->>BrowserJs: saveColumnStateToLocalstorage
    BrowserJs->>Table: invokeMethodAsync(resizeColumnCallback, field, state)
    Table->>Table: ResizeColumnCallback(name, columnState)
    Table->>Table: UpdateTableColumnState(columnState)
    alt OnTableColumnClientStatusChanged assigned
        Table->>AppHandler: OnTableColumnClientStatusChanged(name, _tableColumnStateCache)
    end
    Table->>Table: StateHasChanged()
    end

    rect rgb(230,250,230)
    User->>TablesColumnDrag: click toolbar Reset
    TablesColumnDrag->>TablesColumnDrag: Reset()
    TablesColumnDrag->>Table: ClearTableColumnClientStatus()
    Table->>Table: _tableColumnStateCache.Clear()
    Table->>Table: StateHasChanged()
    end
Loading

File-Level Changes

rendering loop to iterate over the internal _tableColumnStates and emit only for visible columns using their stored Width.
  • Remove the GetColumnFixedWidth extension and all usages so fixed-width handling relies directly on stored column Width values.
  • Ensure ResizeColumnCallback triggers StateHasChanged after updating column state so the new widths are reflected in the UI.
  • markup before and after clearing client state.
  • Adjust the resize-related test to enable FitColumnWidthIncludeHeader for consistency with the new flow.
  • Change Details Files
    Align Table column width persistence with resize callback and column state list usage.
    • Initialize TableColumnClientStatus.Columns with a new list instead of mutating the existing collection in the unit test setup.
    • Change the
    test/UnitTest/Components/TableTest.cs
    src/BootstrapBlazor/Components/Table/Table.razor
    src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
    src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
    src/BootstrapBlazor/Components/Table/Table.razor.cs
    Unify auto-fit column width behavior with resize callback and remove the dedicated AutoFitColumnWidthCallback API.
    • Remove AutoFitColumnWidthCallback from the Table component C# code and its JS-invokable method implementation.
    • Stop passing AutoFitColumnWidthCallback through TableOptions when initializing JS interop for the Table.
    • Update the autoFitColumnWidth JavaScript helper to invoke the existing resizeColumnCallback instead of the removed autoFitColumnWidthCallback.
    • Delete the obsolete OnTableColumnClientStatusChanged_AutoFitColumnWidth_Ok unit test and adjust other tests to cover resize/clear scenarios instead.
    src/BootstrapBlazor/Components/Table/Table.razor.cs
    src/BootstrapBlazor/Components/Table/Table.razor.js
    test/UnitTest/Components/TableTest.cs
    Refine ClearTableColumnClientStatus behavior and tests to validate rendered column widths instead of internal state mutation flags.
    • Remove internal flags (_resetColumns, _invoke) from ClearTableColumnClientStatus so it only clears the cached state and re-renders.
    • Update the ClearTableColumnClientStatus_Ok test to assert column widths via rendered
    src/BootstrapBlazor/Components/Table/Table.razor.cs
    test/UnitTest/Components/TableTest.cs
    Improve TablesColumnDrag sample to demonstrate clearing client-side column status via toolbar and update localized text.
    • Change the sample Table to use a more specific ClientTableName and capture a Table reference via @ref for operations.
    • Add a toolbar template with a Reset button that invokes a new Reset method to call ClearTableColumnClientStatus on the table instance.
    • Update the description block to include text describing ClearTableColumnClientStatus behavior and hook it to localized resources.
    • Implement the backing _table field and Reset method in the TablesColumnDrag code-behind, cleaning up old commented-out sample code.
    • Update localization JSON files to provide strings for the new descriptions and button text, and adjust the project file if needed for resource inclusion.
    src/BootstrapBlazor.Server/Components/Samples/Table/TablesColumnDrag.razor
    src/BootstrapBlazor.Server/Components/Samples/Table/TablesColumnDrag.razor.cs
    src/BootstrapBlazor.Server/Locales/en-US.json
    src/BootstrapBlazor.Server/Locales/zh-CN.json
    src/BootstrapBlazor/BootstrapBlazor.csproj

    Assessment against linked issues

    Issue Objective Addressed Explanation
    #8006 Update the ClearTableColumnClientStatus sample code/documentation to show how to use ClearTableColumnClientStatus with a table (including a reset action).

    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

    @ArgoZhang ArgoZhang merged commit 6baa850 into main May 17, 2026
    6 checks passed
    @ArgoZhang ArgoZhang deleted the refactor-table branch May 17, 2026 07:19
    Copy link
    Copy Markdown
    Contributor

    @sourcery-ai sourcery-ai Bot left a comment

    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:

    • Switching the <colgroup> rendering loop from GetVisibleColumns() to _tableColumnStates means the col order and width now depend entirely on the client state cache; consider what happens when there is no client state (or dynamic column changes) and ensure _tableColumnStates is always populated and ordered consistently with the actual column list, or provide a fallback to GetVisibleColumns() when the cache is empty.
    • After removing AutoFitColumnWidthCallback and routing autoFitColumnWidth through resizeColumnCallback, double‑check that ResizeColumnCallback still receives functionally equivalent data for both manual resizes and auto‑fit, and if necessary distinguish these cases (e.g., via an extra flag or heuristic) instead of relying on them being identical.
    • The removal of restoring col.Width = item.Width in ResetVisibleColumnsCache means clearing client status no longer resets widths to their original values; if the intended behavior is to fully reset user customizations, consider either restoring the original widths here or explicitly documenting that width customizations persist independently of the visible columns cache.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - Switching the `<colgroup>` rendering loop from `GetVisibleColumns()` to `_tableColumnStates` means the col order and width now depend entirely on the client state cache; consider what happens when there is no client state (or dynamic column changes) and ensure `_tableColumnStates` is always populated and ordered consistently with the actual column list, or provide a fallback to `GetVisibleColumns()` when the cache is empty.
    - After removing `AutoFitColumnWidthCallback` and routing `autoFitColumnWidth` through `resizeColumnCallback`, double‑check that `ResizeColumnCallback` still receives functionally equivalent data for both manual resizes and auto‑fit, and if necessary distinguish these cases (e.g., via an extra flag or heuristic) instead of relying on them being identical.
    - The removal of restoring `col.Width = item.Width` in `ResetVisibleColumnsCache` means clearing client status no longer resets widths to their original values; if the intended behavior is to fully reset user customizations, consider either restoring the original widths here or explicitly documenting that width customizations persist independently of the visible columns cache.

    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
    Copy link
    Copy Markdown

    codecov Bot commented May 17, 2026

    Codecov Report

    ✅ All modified and coverable lines are covered by tests.
    ✅ Project coverage is 100.00%. Comparing base (64b5c86) to head (009f6e7).
    ⚠️ Report is 1 commits behind head on main.

    Additional details and impacted files
    @@            Coverage Diff            @@
    ##              main     #8007   +/-   ##
    =========================================
      Coverage   100.00%   100.00%           
    =========================================
      Files          766       766           
      Lines        34131     34123    -8     
      Branches      4692      4691    -1     
    =========================================
    - Hits         34131     34123    -8     
    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 Sentry.
    📢 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.

    Copy link
    Copy Markdown
    Contributor

    Copilot AI left a comment

    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 updates the Table column drag demo and related Table client-state handling so that column resizing and auto-fit width share the same client-status callback flow, and adds a UI reset that clears persisted column state.

    Changes:

    • Update the Table demo to include a “Reset” toolbar button that calls ClearTableColumnClientStatus, and add localized description strings for that behavior.
    • Unify JS auto-fit column width callback to invoke the existing resize callback path, removing the separate AutoFitColumnWidthCallback.
    • Adjust Table <colgroup> rendering and unit tests to assert widths via rendered markup.

    Reviewed changes

    Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

    Show a summary per file
    File Description
    test/UnitTest/Components/TableTest.cs Updates client-state setup and changes assertions to validate rendered <colgroup> widths.
    src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs Removes an internal fixed-width helper previously used by Table colgroup rendering.
    src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs Changes visible-column cache rebuild logic (no longer pushes cached widths into column instances).
    src/BootstrapBlazor/Components/Table/Table.razor.js Routes auto-fit width completion through resizeColumnCallback.
    src/BootstrapBlazor/Components/Table/Table.razor.cs Removes AutoFitColumnWidthCallback, adjusts resize callback, and changes clear-client-state behavior.
    src/BootstrapBlazor/Components/Table/Table.razor Renders <colgroup> from _tableColumnStates instead of GetVisibleColumns().
    src/BootstrapBlazor/BootstrapBlazor.csproj Bumps package version to 10.6.1-beta21.
    src/BootstrapBlazor.Server/Locales/zh-CN.json Adds reset-related localized strings for the demo.
    src/BootstrapBlazor.Server/Locales/en-US.json Adds reset-related localized strings for the demo.
    src/BootstrapBlazor.Server/Components/Samples/Table/TablesColumnDrag.razor.cs Adds @ref-backed table instance and reset method.
    src/BootstrapBlazor.Server/Components/Samples/Table/TablesColumnDrag.razor Adds reset toolbar UI and additional description text.

    💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

    @@ -1894,8 +1893,6 @@ public async Task ClearTableColumnClientStatus()
    // 清除缓存的列状态
    _tableColumnStateCache.Clear();

    Comment on lines 563 to 573
    var item = _tableColumnStates[index];
    if (item.Visible)
    {
    var col = Columns.Find(c => c.GetFieldName() == item.Name);
    if (col != null)
    {
    item.DisplayName = col.GetDisplayName();

    // 恢复宽度
    col.Width = item.Width;

    // 增加到可见列缓存集合
    _visibleColumnsCache.Add(col);
    }
    <col style="@GetColWidthString(col.GetColumnFixedWidth(DefaultFixedColumnWidth))" />
    if (col.Visible)
    {
    <col style="@GetColWidthString(col.Width)" />
    <section ignore>@((MarkupString)Localizer["AllowDragOrderDesc"].Value)</section>
    <Table TItem="Foo" ClientTableName="table-test"
    <section ignore>
    <p>@((MarkupString)Localizer["AllowDragOrderDesc"].Value)</p>
    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.

    doc(Table): update ClearTableColumnClientStatus sample code

    2 participants