Skip to content

feat(Table): add SetRowStyleFormatter parameter#7758

Merged
ArgoZhang merged 3 commits intomainfrom
feat-table
Mar 10, 2026
Merged

feat(Table): add SetRowStyleFormatter parameter#7758
ArgoZhang merged 3 commits intomainfrom
feat-table

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Mar 10, 2026

Link issues

fixes #7757

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

Add support for per-row inline style customization in the Table component.

New Features:

  • Introduce a SetRowStyleFormatter parameter on Table to allow consumers to provide row-level inline styles.
  • Apply the computed row style to table body rows via the DynamicElement wrapper.

Tests:

  • Extend existing Table row formatting tests to cover the new SetRowStyleFormatter behavior.

Copilot AI review requested due to automatic review settings March 10, 2026 01:41
@bb-auto bb-auto bot added the enhancement New feature or request label Mar 10, 2026
@bb-auto bb-auto bot added this to the v10.4.0 milestone Mar 10, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 10, 2026

Reviewer's Guide

Adds a new SetRowStyleFormatter parameter to Table to allow per-row inline style customization and wires it through the rendering pipeline, with a corresponding unit test to verify the style output.

Sequence diagram for applying SetRowStyleFormatter during row rendering

sequenceDiagram
    participant Table_TItem_ as Table_TItem_
    participant RenderRow as RenderRow_lambda
    participant DynamicElement as DynamicElement_tr
    participant CssBuilder as CssBuilder
    participant Formatter as SetRowStyleFormatter

    Table_TItem_->>RenderRow: Invoke for item
    RenderRow->>Table_TItem_: GetRowClassString(item)
    RenderRow->>Table_TItem_: GetRowStyleString(item)
    activate Table_TItem_
    Table_TItem_->>CssBuilder: Default()
    activate CssBuilder
    CssBuilder-->>Table_TItem_: CssBuilder
    Table_TItem_->>Formatter: Invoke(item)
    activate Formatter
    Formatter-->>Table_TItem_: string? inlineStyle
    deactivate Formatter
    Table_TItem_->>CssBuilder: AddClass(inlineStyle)
    CssBuilder-->>Table_TItem_: CssBuilder
    Table_TItem_->>CssBuilder: Build()
    CssBuilder-->>Table_TItem_: string? styleString
    deactivate CssBuilder
    Table_TItem_-->>RenderRow: styleString
    deactivate Table_TItem_
    RenderRow->>DynamicElement: new tr with class and style=styleString
    DynamicElement-->>RenderRow: rendered row fragment
    RenderRow-->>Table_TItem_: row fragment for item
Loading

Class diagram for new SetRowStyleFormatter support in Table

classDiagram
    class Table_TItem_ {
        +Func~TItem, string?~? SetRowClassFormatter
        +Func~TItem, string?~? SetRowStyleFormatter
        +string? GetRowClassString(TItem item, string additionalClass)
        +string? GetRowClassString(TItem item)
        +string? GetRowStyleString(TItem item)
        RenderFragment~TItem~ RenderRow
    }

    class CssBuilder {
        +static CssBuilder Default()
        +CssBuilder AddClass(string? value)
        +string Build()
    }

    class DynamicElement {
        +string? TagName
        +string? class
        +string? style
        +bool TriggerContextMenu
        +EventCallback OnContextMenu
        +EventCallback OnClick
    }

    Table_TItem_ --> CssBuilder : uses
    Table_TItem_ --> DynamicElement : renders rows with
    Table_TItem_ o--> SetRowStyleFormatter : row_style_delegate
Loading

File-Level Changes

Change Details Files
Expose a new row style formatter callback on Table and use it when rendering table rows.
  • Add SetRowStyleFormatter parameter to Table with XML documentation in both Chinese and English.
  • Introduce GetRowStyleString helper that builds the inline style string using CssBuilder and the SetRowStyleFormatter callback.
  • Update DynamicElement usage in Table.razor to apply the computed inline style via the style attribute for both standard and templated row rendering paths.
src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs
src/BootstrapBlazor/Components/Table/Table.razor.cs
src/BootstrapBlazor/Components/Table/Table.razor
Extend existing unit tests to cover the new row style formatter behavior.
  • Add SetRowStyleFormatter configuration to the existing SetRowClassFormatter_Ok test.
  • Assert that the rendered output contains the expected inline style string produced by the formatter.
test/UnitTest/Components/TableTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7757 Add a SetRowStyleFormatter parameter/callback to the Table component that allows returning a per-row inline style string.
#7757 Apply the SetRowStyleFormatter output to the rendered table rows so that the returned style string appears in the row's style attribute.

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 9c0cecd into main Mar 10, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the feat-table branch March 10, 2026 01:42
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 - 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.

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7758   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          750       750           
  Lines        33270     33274    +4     
  Branches      4612      4613    +1     
=========================================
+ Hits         33270     33274    +4     
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
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 implements the SetRowStyleFormatter feature requested in issue #7757. The existing SetRowClassFormatter parameter only allows returning a CSS class name (which must be pre-defined in a stylesheet), but users wanted a way to set inline styles directly (e.g., "color:red;font-size:15px;") without needing to pre-define styles in a CSS file.

Changes:

  • Adds a SetRowStyleFormatter parameter (Func<TItem, string?>) to the Table component alongside the existing SetRowClassFormatter
  • Adds a GetRowStyleString helper method that invokes SetRowStyleFormatter and applies the result to both Table and CardView row elements via a new style attribute
  • Bumps the package version from 10.4.1-beta01 to 10.4.1-beta02 and adds a unit test for the new parameter

Reviewed changes

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

Show a summary per file
File Description
src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs Adds the new SetRowStyleFormatter parameter definition with bilingual XML docs
src/BootstrapBlazor/Components/Table/Table.razor.cs Adds GetRowStyleString() helper method that builds the inline style string
src/BootstrapBlazor/Components/Table/Table.razor Applies style="@GetRowStyleString(item)" to row elements in both Table mode and CardView mode
src/BootstrapBlazor/BootstrapBlazor.csproj Version bump to 10.4.1-beta02
test/UnitTest/Components/TableTest.cs Extends SetRowClassFormatter_Ok test to also cover SetRowStyleFormatter

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

public Func<TItem, string?>? SetRowClassFormatter { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 行样式格式回调委托</para>
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The Chinese documentation (lang="zh") for SetRowStyleFormatter is identical to the one for SetRowClassFormatter above it: both use "获得/设置 行样式格式回调委托". This is misleading — SetRowClassFormatter deals with CSS class names while SetRowStyleFormatter deals with inline CSS style strings. The zh-CN doc for SetRowStyleFormatter should be updated to distinguish it, such as "获得/设置 行内联样式格式回调委托" (inline style formatter callback).

Copilot uses AI. Check for mistakes.
RenderFragment<TItem> RenderRow => item =>
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="GetKeyByITem(item)"
@<DynamicElement @key="GetKeyByITem(item)" TagName="tr"
class="@GetRowClassString(item)" style="@GetRowStyleString(item)"
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

There is a trailing whitespace at the end of the style="@GetRowStyleString(item)" attribute line. While this is not functionally harmful, it's a minor style issue and the codebase should ideally be free of unnecessary trailing whitespace.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +142
/// <summary>
/// <para lang="zh">获得 Body 内行内联样式</para>
/// <para lang="en">Get Body Row Inline Style</para>
/// </summary>
protected string? GetRowStyleString(TItem item) => CssBuilder.Default()
.AddClass(SetRowStyleFormatter?.Invoke(item))
.Build();
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The GetRowStyleString method is missing a <param name="item"> XML documentation tag, while similar methods in the same file (GetRowClassString, GetDetailBarClassString, GetDetailRowClassString, GetDetailCaretClassString) all document their item parameter.

Copilot uses AI. Check for mistakes.
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.

feat(Table): 能否提供一个如SetRowStyleFormatter的方法

2 participants