Skip to content

feat(Table): make sure TableColumnStateCache work without localstorage#7981

Merged
ArgoZhang merged 2 commits into
mainfrom
fix-table
May 12, 2026
Merged

feat(Table): make sure TableColumnStateCache work without localstorage#7981
ArgoZhang merged 2 commits into
mainfrom
fix-table

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 12, 2026

Link issues

fixes #7980

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

Ensure table column state cache is kept in sync with table columns even when no persisted client-side storage is available.

New Features:

  • Initialize column state cache entries from current table columns when no prior cached state exists.

Enhancements:

  • Always update the in-memory column state cache when columns are reordered via drag-and-drop, independent of client-side table name configuration.

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

sourcery-ai Bot commented May 12, 2026

Reviewer's Guide

Ensures the Table column state cache is always kept in sync with the current columns (even when localStorage is unavailable) by rebuilding missing column entries from live columns and always updating cached column order on drag operations.

Flow diagram for updated RebuildTableColumnFromCache behavior

flowchart TD
    A[Start RebuildTableColumnFromCache] --> B[Loop Columns]
    B --> C[GetFieldName]
    C --> D[Find column in _tableColumnStateCache.Columns by Name]
    D -->|column == null| E[Create new TableColumnState
Name, Width, Visible, DisplayName from col]
    E --> F[Add TableColumnState to _tableColumnStateCache.Columns]
    D -->|column != null| G[Set col.Width and col.Visible
from existing TableColumnState]
    G --> H[Update TableColumnState.DisplayName
from col]
    F --> I{More Columns?}
    H --> I
    I -->|Yes| B
    I -->|No| J[End RebuildTableColumnFromCache]
Loading

Flow diagram for updated DragColumnCallback column order caching

flowchart TD
    A[Start DragColumnCallback] --> B[Remove firstColumn from _tableColumnStates]
    B --> C[Insert firstColumn at currentIndex in _tableColumnStates]
    C --> D[Clear _tableColumnStateCache.Columns]
    D --> E[AddRange _tableColumnStates to _tableColumnStateCache.Columns]
    E --> F{OnDragColumnEndAsync != null?}
    F -->|Yes| G[Invoke OnDragColumnEndAsync]
    F -->|No| H[End DragColumnCallback]
    G --> H
Loading

File-Level Changes

Change Details Files
Rebuild column state cache entries for all columns, creating missing cache items from the live column configuration.
  • Iterate over all Columns unconditionally instead of only when the cache already contains entries.
  • For each column, find its entry in the in-memory _tableColumnStateCache by field name.
  • If the cache entry does not exist, create a new TableColumnState populated from the current column’s width, visibility, and display name and add it to the cache.
  • If the cache entry exists, apply its width and visibility to the live column and refresh the cached DisplayName from the column.
src/BootstrapBlazor/Components/Table/Table.razor.cs
Always synchronize cached column order with _tableColumnStates after drag-and-drop operations, independent of client-side table name/localStorage configuration.
  • Remove the conditional guard that required a non-empty ClientTableName before updating the cached column order.
  • After a drag operation, clear the cache column list and repopulate it from _tableColumnStates to reflect the new order.
src/BootstrapBlazor/Components/Table/Table.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7980 Ensure table column width and visibility state is cached and applied even when local-storage-based caching (e.g., ClientTableName) is not enabled.
#7980 Ensure column order changes update the in-memory TableColumnStateCache regardless of whether local-storage-based caching (ClientTableName) is configured.

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

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:

  • In RebuildTableColumnFromCache, repeatedly calling List.Find inside the foreach leads to O(n^2) behavior for many columns; consider building a Dictionary<string, TableColumnState> from _tableColumnStateCache.Columns first to avoid repeated linear scans.
  • When creating a new TableColumnState in RebuildTableColumnFromCache, you’re using col.GetVisible() but later always writing back to col.Visible; if there’s any difference between these, it might be clearer to standardize on one source of truth for visibility to avoid subtle inconsistencies.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `RebuildTableColumnFromCache`, repeatedly calling `List.Find` inside the `foreach` leads to O(n^2) behavior for many columns; consider building a `Dictionary<string, TableColumnState>` from `_tableColumnStateCache.Columns` first to avoid repeated linear scans.
- When creating a new `TableColumnState` in `RebuildTableColumnFromCache`, you’re using `col.GetVisible()` but later always writing back to `col.Visible`; if there’s any difference between these, it might be clearer to standardize on one source of truth for visibility to avoid subtle inconsistencies.

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 ArgoZhang merged commit c16b4db into main May 12, 2026
3 of 4 checks passed
@ArgoZhang ArgoZhang deleted the fix-table branch May 12, 2026 03:17
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 targets the Table component’s column-state caching so that TableColumnStateCache is maintained even when ClientTableName (localStorage persistence) is not configured, addressing #7980.

Changes:

  • Populate _tableColumnStateCache.Columns from current Columns when no cached entry exists.
  • Update _tableColumnStateCache.Columns ordering on drag regardless of ClientTableName.

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

Comment on lines +1362 to +1366
// 设置列宽度与可见性
var column = _tableColumnStateCache.Columns.Find(i => i.Name == fieldName);
if (column == null)
{
column = new TableColumnState()
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.

refactor(Table): 列信息缓存在没有本地缓存模式下也生效

2 participants