Skip to content

doc(Table): update dyanmic datatable sample#8103

Merged
ArgoZhang merged 11 commits into
mainfrom
doc-dynamic-table
Jun 11, 2026
Merged

doc(Table): update dyanmic datatable sample#8103
ArgoZhang merged 11 commits into
mainfrom
doc-dynamic-table

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jun 11, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #8102

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

Refine the dynamic DataTable sample implementation and documentation to better demonstrate multi-context usage and efficient pagination updates.

Enhancements:

  • Refactor dynamic DataTable sample to use separate contexts for each demo scenario and share reusable DataTable creation logic.
  • Optimize pagination sample to update rows within an existing DataTableDynamicContext instead of recreating the context on page changes.
  • Clean up dynamic object sample utilities, including random value generation and row data creation.

Documentation:

  • Expand the dynamic DataTable demo page with explanatory notes and inline code examples showing how to implement server-side-style pagination with DataTableDynamicContext.
  • Update localization resources to support the new documentation content on the dynamic DataTable sample.

Copilot AI review requested due to automatic review settings June 11, 2026 00:50
@bb-auto bb-auto Bot added the documentation Improvements or additions to documentation label Jun 11, 2026
@bb-auto bb-auto Bot added this to the v10.7.0 milestone Jun 11, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refactors the dynamic DataTable sample to use multiple explicit DataTableDynamicContext instances (including a cached paging example), updates the Razor demo wiring and docs accordingly, and performs a small cleanup in the dynamic object sample helper.

Sequence diagram for the updated paging DataTableDynamicContext flow

sequenceDiagram
    actor User
    participant Pagination
    participant TablesDynamic
    participant DataTableDynamicContext as _dataTableDynamicContext4
    participant DataTable as _pageDataTable

    User->>Pagination: click page link
    Pagination->>TablesDynamic: OnPageLinkClick(pageIndex)
    activate TablesDynamic
    TablesDynamic->>TablesDynamic: PageIndex = pageIndex
    TablesDynamic->>TablesDynamic: UpdatePageDataContext()
    activate TablesDynamic
    TablesDynamic->>DataTableDynamicContext: get DataTable
    DataTableDynamicContext-->>TablesDynamic: _dataTableDynamicContext4.DataTable
    TablesDynamic->>DataTable: Rows.Clear()
    loop for each f in _pageData.Skip(...).Take(...)
        TablesDynamic->>DataTable: Rows.Add(f.Id, f.DateTime, f.Name, f.Count)
    end
    TablesDynamic->>DataTable: AcceptChanges()
    deactivate TablesDynamic
    TablesDynamic->>TablesDynamic: StateHasChanged()
    TablesDynamic-->>Pagination: Task.CompletedTask
    deactivate TablesDynamic
Loading

File-Level Changes

Change Details Files
Refactor dynamic DataTable initialization to use reusable factory methods and multiple DataTableDynamicContext instances for different demo scenarios.
  • Replace single DataTableDynamicContext/DataTable fields with four context fields for separate demos.
  • Introduce CreateDataTable and CreateContext helpers to build DataTables and configure DataTableDynamicContext behavior (column attributes, delete and change handlers).
  • Consolidate initialization into InitDataTableContext, which creates three independent in‑memory contexts and a paged context.
  • Use Localizer-driven text for newly added items instead of hardcoded Chinese text.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor.cs
Improve dynamic column add/remove behavior to operate on a specific DataTableDynamicContext instance.
  • Update OnAddColumn/OnRemoveColumn to work against _dataTableDynamicContext3.DataTable rather than a shared DataTable.
  • After column schema changes, accept changes and recreate only the affected context instead of all contexts.
  • Ensure table state is refreshed via StateHasChanged after structural updates.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor.cs
Rework paging DataTable sample to separate data storage from the DataTable and avoid recreating the paging context on every page change.
  • Introduce _pageData backing list and _pageDataTable for the paged sample instead of PageFoos/PageDataTable.
  • Create CreatePageDataTable and CreatePageDataContext helpers to initialize the initial DataTable and DataTableDynamicContext for paging with UseCache disabled.
  • Add UpdatePageDataContext to only repopulate rows in the existing DataTable on page changes, called from OnPageLinkClick.
  • Align paging column metadata/validation with FooLocalizer and adjust localization keys.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor.cs
Update Razor sample markup to bind to the new context fields and document the paging optimization pattern.
  • Bind each demo instance to its corresponding _dataTableDynamicContextX field instead of the removed DataTableDynamicContext/DataTablePageDynamicContext.
  • Add an explanatory note and code snippet showing CreatePageDataContext/UpdatePageDataContext usage before the demos.
  • Adjust Table and Pagination elements to explicit start/end tags and align with new context names.
  • src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor
    Minor cleanup in dynamic object sample utility code for readability and style.
    • Rename random to Random and make it a static readonly field following .NET naming conventions.
    • Simplify GenerateDynamicRowData to ignore the index parameter, iterate directly over _dynamicColumnList, and use the shared Random instance.
    src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamicObject.razor.cs
    Localization entries updated to support new explanatory text and labels for the dynamic table sample (content not shown in diff).
    • Extend en-US.json with new keys used in the updated TablesDynamic Razor view (e.g., note title/body and new-value text).
    • Extend zh-CN.json with corresponding localized strings for the new dynamic table sample explanations.
    src/BootstrapBlazor.Server/Locales/en-US.json
    src/BootstrapBlazor.Server/Locales/zh-CN.json

    Assessment against linked issues

    Issue Objective Addressed Explanation
    #8102 Update the dynamic DataTable sample implementation to use the new pattern (separate DataTableDynamicContext instances, refactored pagination handling with CreatePageDataContext/UpdatePageDataContext, and improved dynamic column handling).
    #8102 Update the dynamic DataTable sample documentation/demo markup to reflect the new implementation and explain how to use the new pagination DataTableDynamicContext pattern.

    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

@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 found 1 issue, and left some high level feedback:

  • The four separate DataTableDynamicContext fields (_dataTableDynamicContext14) are a bit opaque; consider either using more descriptive names (e.g., _listContext, _editContext, _dynamicColumnsContext, _pagingContext) or grouping them into a small struct/class to clarify their distinct purposes.
  • In OnAddColumn and OnRemoveColumn you rely on _dataTableDynamicContext3!; if this context is required for those interactions it may be clearer to enforce non-nullability (e.g., via initialization guarantees or a guard) instead of relying on the null-forgiving operator.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The four separate `DataTableDynamicContext` fields (`_dataTableDynamicContext1``4`) are a bit opaque; consider either using more descriptive names (e.g., `_listContext`, `_editContext`, `_dynamicColumnsContext`, `_pagingContext`) or grouping them into a small struct/class to clarify their distinct purposes.
- In `OnAddColumn` and `OnRemoveColumn` you rely on `_dataTableDynamicContext3!`; if this context is required for those interactions it may be clearer to enforce non-nullability (e.g., via initialization guarantees or a guard) instead of relying on the null-forgiving operator.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor.cs" line_range="15-18" />
<code_context>
-    private DataTableDynamicContext? DataTableDynamicContext { get; set; }
-
-    private DataTable UserData { get; } = new DataTable();
+    private DataTableDynamicContext? _dataTableDynamicContext1;
+    private DataTableDynamicContext? _dataTableDynamicContext2;
+    private DataTableDynamicContext? _dataTableDynamicContext3;
+    private DataTableDynamicContext? _dataTableDynamicContext4;

     private List<DynamicObject> SelectedItems { get; set; } = [];
</code_context>
<issue_to_address>
**suggestion:** Numbered context fields make the usage harder to follow and more error-prone as the file grows.

The `_dataTableDynamicContext1``4` naming makes it hard to know which context belongs to which table scenario without tracing references through the file, and increases the chance of wiring the wrong context in the `.razor` file. Please rename these to scenario-specific identifiers (e.g. `_mainContext`, `_editableContext`, `_dynamicColumnsContext`, `_pagedContext`) so the intent and bindings are clearer.

Suggested implementation:

```csharp
public partial class TablesDynamic
{
    // Context for the primary/basic table scenario
    private DataTableDynamicContext? _mainContext;

    // Context for the editable table scenario
    private DataTableDynamicContext? _editableContext;

    // Context for the dynamic columns table scenario
    private DataTableDynamicContext? _dynamicColumnsContext;

    // Context for the paged table scenario
    private DataTableDynamicContext? _pagedContext;

    private List<DynamicObject> SelectedItems { get; set; } = [];

```

To fully apply this refactor, you should also:

1. Replace all usages of `_dataTableDynamicContext1` with `_mainContext` within `TablesDynamic.razor.cs` and `TablesDynamic.razor` (e.g. `Context="_mainContext"`).
2. Replace all usages of `_dataTableDynamicContext2` with `_editableContext`.
3. Replace all usages of `_dataTableDynamicContext3` with `_dynamicColumnsContext`.
4. Replace all usages of `_dataTableDynamicContext4` with `_pagedContext`.
5. If any of the contexts actually map to different scenarios than "main/editable/dynamicColumns/paged", adjust the field names and comments accordingly to match the real usage.
</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.

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

Updates the Table Dynamic sample documentation and implementation to better demonstrate DataTableDynamicContext usage across multiple scenarios, including more efficient pagination updates and new localized explanatory notes.

Changes:

  • Refactors the dynamic DataTable sample to use multiple DataTableDynamicContext instances and shared creation helpers.
  • Improves the pagination demo to update the existing DataTable rows instead of recreating the dynamic context on each page change (with UseCache = false).
  • Adds new localized “Notes” content for the dynamic table sample (en-US / zh-CN), plus minor cleanup in the dynamic object sample.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/BootstrapBlazor.Server/Locales/zh-CN.json Adds new zh-CN localized strings for dynamic table notes and “new row” default text.
src/BootstrapBlazor.Server/Locales/en-US.json Adds new en-US localized strings for dynamic table notes and “new row” default text.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamicObject.razor.cs Minor refactor/cleanup of random generation and dynamic row data construction.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor.cs Refactors sample contexts, adds paging context update method, and adjusts dynamic context creation logic.
src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor Expands the demo page with new notes + inline sample code and updates bindings to new contexts.

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

Comment thread src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor Outdated
Comment thread src/BootstrapBlazor.Server/Components/Samples/Table/TablesDynamic.razor.cs Outdated
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8103   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34204     34204           
  Branches      4696      4696           
=========================================
  Hits         34204     34204           
Flag Coverage Δ
BB 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.

@ArgoZhang ArgoZhang merged commit bc95157 into main Jun 11, 2026
4 checks passed
@ArgoZhang ArgoZhang deleted the doc-dynamic-table branch June 11, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(Table): update dyanmic datatable sample

2 participants