Skip to content

Conversation

@yacper
Copy link
Contributor

@yacper yacper commented Jun 16, 2025

Issues

close #6249

Summary By Copilot

Regression?

  • [ x] Yes
  • No

Risk

  • High
  • Medium
  • [x ] Low

Verification

  • [ x] Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • [x ] 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

Bug Fixes:

  • Re-sort Table columns when their Order property is changed in the OnColumnCreating callback to reflect the updated ordering.

Summary by Sourcery

Fix table column ordering in the OnColumnCreating callback by deferring the column list update until after ordering is applied, and ensure column widths and visibility resets operate on the updated columns collection.

Bug Fixes:

  • Reapply the modified column order after invoking OnColumnCreating by moving Columns.Clear/AddRange post-callback
  • Pass the dynamic column list into ResetColumnWidth and InternalResetVisibleColumns to reflect updated ordering

Enhancements:

  • Convert ColumnWidth from a class to a struct to reduce allocations
  • Refactor ResetColumnWidth and InternalResetVisibleColumns to accept the target columns list explicitly

Copilot AI review requested due to automatic review settings June 16, 2025 10:40
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 16, 2025

Reviewer's Guide

This PR fixes the table component’s column reordering and width/visibility persistence by threading the updated column list through various lifecycle methods, refactors several reset/reload methods to accept explicit column collections, and converts the ColumnWidth helper from a class to a struct for value semantics.

Class diagram for refactored Table column management

classDiagram
    class Table {
        +List<ITableColumn> Columns
        +void ResetColumnWidth(List<ITableColumn> columns)
        +Task ReloadColumnWidthFromBrowserAsync(List<ITableColumn> columns)
        +Task ReloadColumnOrdersFromBrowserAsync(List<ITableColumn> columns)
        +void InternalResetVisibleColumns(List<ITableColumn> columns, IEnumerable<ColumnVisibleItem>? items = null)
        +void ResetVisibleColumns(IEnumerable<ColumnVisibleItem> columns)
    }
    class ColumnWidth {
        +string Name
        +int Width
    }
    Table o-- "*" ITableColumn
    Table o-- "*" ColumnVisibleItem
    Table o-- "*" ColumnWidth
    note for Table "Methods now accept explicit column lists for correct ordering and persistence."
    note for ColumnWidth "Now a struct instead of a class."
Loading

Class diagram for ColumnWidth struct change

classDiagram
    class ColumnWidth {
        +string Name
        +int Width
    }
    note for ColumnWidth "ColumnWidth is now a struct (was a class) for value semantics."
Loading

File-Level Changes

Change Details Files
Ensure updated column ordering and persisted settings are applied in OnColumnCreating
  • Pass the local cols list into OnColumnCreating, ReloadColumnWidthFromBrowserAsync, ResetColumnWidth, and InternalResetVisibleColumns
  • Reorder Columns only after invoking OnColumnCreating and resetting widths/visibility
  • Use cols.OrderFunc() instead of always manipulating the Columns collection directly
Table/Table.razor.cs
Refactor reset and reload routines to accept explicit column lists
  • Change signatures of ResetColumnWidth, ReloadColumnWidthFromBrowserAsync, InternalResetVisibleColumns, and ResetVisibleColumns to take specific column list parameters
  • Update calls in lifecycle hooks and toolbar code to pass the correct column collection
Table/Table.razor.cs
Table/Table.razor.Toolbar.cs
Convert ColumnWidth helper to a struct
  • Replace the ColumnWidth class declaration with a struct for value semantics
  • Ensure existing width serialization logic remains compatible
Table/ColumnWidth.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6249 Fix the bug where updating the table column order in the OnColumnCreating event does not work as expected.
#6249 Ensure that persisted column widths are correctly applied after reordering columns.

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

bb-auto bot commented Jun 16, 2025

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

@bb-auto bb-auto bot requested a review from ArgoZhang June 16, 2025 10:40
Copy link
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 fixes an issue in the Table control where changes to a Column’s Order property in the OnColumnCreating callback were not applied. The changes include creating a copy of each column’s initial Order, comparing after the callback, and reordering the Columns collection if any changes are detected.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 16, 2025
Copy link
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 @yacper - I've reviewed your changes and they look great!


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.

@ArgoZhang
Copy link
Member

@yacper 感谢提交 PR 看一下 https://www.bilibili.com/video/BV1wBM4zDEnn/?spm_id_from=333.999.0.0 把 CLA 签署一下

@yacper
Copy link
Contributor Author

yacper commented Jun 17, 2025

@microsoft-github-policy-service agree

@ArgoZhang ArgoZhang changed the title bugfix: Table控件中,如果OnColumnCreating回调中修改了Column项的Order,并不会起作用 fix(Table): update table column order in OnColumnCreating not work Jun 18, 2025
@bb-auto bb-auto bot added the bug Something isn't working label Jun 18, 2025
@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 18, 2025
@ArgoZhang
Copy link
Member

@sourcery-ai review

@codecov
Copy link

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e6c8012) to head (644fcb7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6242   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          704       704           
  Lines        31130     31130           
  Branches      4402      4402           
=========================================
  Hits         31130     31130           
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.

@ArgoZhang ArgoZhang merged commit 1469626 into dotnetcore:main Jun 18, 2025
5 checks passed
Copy link
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 @yacper - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.cs:1177` </location>
<code_context>
         }

         await ReloadColumnOrdersFromBrowserAsync(cols);
-        Columns.Clear();
-        Columns.AddRange(cols.OrderFunc());

         // 查看是否开启列宽序列化
</code_context>

<issue_to_address>
Columns is cleared and repopulated after InternalResetVisibleColumns, which now takes cols instead of Columns.

If InternalResetVisibleColumns should use the updated columns, move Columns.Clear/AddRange before calling it.
</issue_to_address>

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.

Comment on lines 1177 to 1178

await ReloadColumnOrdersFromBrowserAsync(cols);
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Columns is cleared and repopulated after InternalResetVisibleColumns, which now takes cols instead of Columns.

If InternalResetVisibleColumns should use the updated columns, move Columns.Clear/AddRange before calling it.

Copy link
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 @yacper - I've reviewed your changes and they look great!


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.

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.

bug(Table): update table column order in OnColumnCreating not work

2 participants