Skip to content

Conversation

ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Oct 11, 2025

Link issues

fixes #6864

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 FitColumnWidthIncludeHeader parameter to Table to optionally include header cells in auto-fit column width calculations.

New Features:

  • Introduce FitColumnWidthIncludeHeader parameter to control inclusion of header cell when auto-fitting column widths

Enhancements:

  • Implement header width consideration in the JavaScript auto-fit logic based on the new parameter

AApuci and others added 14 commits October 11, 2025 10:14
Modified the OnAutoFitContentAsync callback to accept the calculated column width as a parameter in both C# and JavaScript. This allows custom logic to consider the current width when determining the final column width, improving flexibility for auto-fit scenarios.

Co-Authored-By: ljmay168 <209402714+ljmay168@users.noreply.github.com>
修改 单元测试宽度计算

Signed-off-by: AApuci <44996451+AApuci@users.noreply.github.com>
# Conflicts:
#	src/BootstrapBlazor/Components/Table/Table.razor.cs
@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 05:28
Copy link
Contributor

sourcery-ai bot commented Oct 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces a new FitColumnWidthIncludeHeader toggle on the Table component to optionally include header cell width during auto-fit calculations, with corresponding updates to the JS autoFitColumnWidth logic.

Class diagram for updated Table component parameters

classDiagram
class Table {
  +Func<string, float, Task<float>>? OnAutoFitColumnWidthCallback
  +bool FitColumnWidthIncludeHeader
}
Loading

Flow diagram for autoFitColumnWidth logic with FitColumnWidthIncludeHeader

flowchart TD
    A["autoFitColumnWidth called"] --> B["Calculate maxWidth from data cells"]
    B --> C{fitColumnWidthIncludeHeader?}
    C -- Yes --> D["Include header cell width in maxWidth"]
    C -- No --> E["Skip header cell width"]
    D --> F["Invoke autoFitColumnWidthCallback if set"]
    E --> F
    F --> G["Set column width"]
Loading

File-Level Changes

Change Details Files
Add FitColumnWidthIncludeHeader parameter to the Table component
  • Define [Parameter] property FitColumnWidthIncludeHeader with default false
  • Include FitColumnWidthIncludeHeader in the JS options passed in OnTableRenderAsync
src/BootstrapBlazor/Components/Table/Table.razor.cs
Integrate header inclusion logic in JS auto-fit operation
  • Check table.options.fitColumnWidthIncludeHeader before measuring header width
  • Calculate header cell width using calcCellWidth and update maxWidth
src/BootstrapBlazor/Components/Table/Table.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#6864 When auto-fitting column width (e.g., double-clicking the table header), ensure that both the header and body content are considered so that both are fully visible.

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 bb-auto bot added the enhancement New feature or request label Oct 11, 2025
@bb-auto bb-auto bot added this to the 9.11.0 milestone Oct 11, 2025
Copy link
Contributor

@Copilot 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 adds a new parameter FitColumnWidthIncludeHeader to the Table component that allows including header cell width when auto-fitting column widths. This enhancement provides more control over the column width calculation behavior.

  • Added FitColumnWidthIncludeHeader boolean parameter to control header inclusion in width calculations
  • Updated JavaScript auto-fit logic to consider header cell width when the parameter is enabled
  • Enhanced the table options configuration to pass the new parameter to the client-side code

Reviewed Changes

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

File Description
Table.razor.cs Added new boolean parameter FitColumnWidthIncludeHeader and included it in table options
Table.razor.js Updated autoFitColumnWidth function to include header cell width calculation when enabled

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Oct 11, 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 there - I've reviewed your changes - here's some feedback:

  • Add a null check around col.closest('th') in the JavaScript autoFitColumnWidth logic to prevent runtime errors when a header cell isn’t found.
  • Translate or supplement the Chinese XML doc comment on FitColumnWidthIncludeHeader into English to match the surrounding codebase style.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Add a null check around col.closest('th') in the JavaScript autoFitColumnWidth logic to prevent runtime errors when a header cell isn’t found.
- Translate or supplement the Chinese XML doc comment on FitColumnWidthIncludeHeader into English to match the surrounding codebase style.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.js:745-749` </location>
<code_context>
         maxWidth = Math.max(maxWidth, calcCellWidth(cell));
     });

+    if (table.options.fitColumnWidthIncludeHeader) {
+        const th = col.closest('th');
+        const span = th.querySelector('.table-cell');
+        maxWidth = Math.max(maxWidth, calcCellWidth(span));
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Consider null-checking 'th' and 'span' before using them.

Without null checks, calling 'calcCellWidth(span)' may cause runtime errors if the DOM structure is not as expected.

```suggestion
    if (table.options.fitColumnWidthIncludeHeader) {
        const th = col.closest('th');
        if (th) {
            const span = th.querySelector('.table-cell');
            if (span) {
                maxWidth = Math.max(maxWidth, calcCellWidth(span));
            }
        }
    }
```
</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.

Copy link

codecov bot commented Oct 11, 2025

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6871   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31763     31765    +2     
  Branches      4466      4466           
=========================================
+ Hits         31763     31765    +2     
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 6570642 into main Oct 11, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the feat-table-column branch October 11, 2025 05:33
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): 自适应列宽时建议同时适应表头和表体内容宽度

2 participants