doc(Table): update ClearTableColumnClientStatus sample code#8007
Conversation
Reviewer's GuideUpdates 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 behaviorsequenceDiagram
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
File-Level Changesrendering loop to iterate over the internal _tableColumnStates and emit only for visible columns using their stored Width.
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Switching the
<colgroup>rendering loop fromGetVisibleColumns()to_tableColumnStatesmeans 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_tableColumnStatesis always populated and ordered consistently with the actual column list, or provide a fallback toGetVisibleColumns()when the cache is empty. - After removing
AutoFitColumnWidthCallbackand routingautoFitColumnWidththroughresizeColumnCallback, double‑check thatResizeColumnCallbackstill 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.WidthinResetVisibleColumnsCachemeans 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.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 #8007 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 766 766
Lines 34131 34123 -8
Branches 4692 4691 -1
=========================================
- Hits 34131 34123 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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(); | |||
|
|
|||
| 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> |
Link issues
fixes #8006
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Adjust table column width persistence and sample usage for client-side column state clearing and resizing.
Bug Fixes:
Enhancements:
Documentation:
Tests: