Skip to content

Improve QuickGrid diagnostics for mismatched GridSort types#67413

Open
BharatRamsf3693 wants to merge 7 commits into
dotnet:mainfrom
BharatRamsf3693:bug-56437-quickgrid-gridsort-mismatch
Open

Improve QuickGrid diagnostics for mismatched GridSort types#67413
BharatRamsf3693 wants to merge 7 commits into
dotnet:mainfrom
BharatRamsf3693:bug-56437-quickgrid-gridsort-mismatch

Conversation

@BharatRamsf3693

@BharatRamsf3693 BharatRamsf3693 commented Jun 25, 2026

Copy link
Copy Markdown

Improve QuickGrid diagnostics for mismatched GridSort types

Description

This change improves the developer experience when a GridSort<TSortItem> type does not match the QuickGrid<TGridItem> item type used by a TemplateColumn.

Previously, configuring a TemplateColumn with a GridSort created for a different item type could cause the column to fail initialization with an unclear error, making the root cause difficult to identify. This update adds an explicit validation check during TemplateColumn initialization and throws a more actionable exception when the column cannot bind to the parent grid due to a type mismatch.

Before

image

After

image

Changes included

  • Added validation in TemplateColumn<TGridItem> during component initialization.
  • Detects scenarios where the column cannot attach to the parent QuickGrid because of an item-type mismatch.
  • Throws a clear InvalidOperationException with guidance to verify that the GridSort type parameter matches the grid's item type.
  • Improves diagnostics by including:
    • The column title when available, or (unnamed) when not specified.
    • The column's TGridItem type.
    • A clear indication that the parent QuickGrid item type does not match.

Example exception

Column '<column-name>' has TGridItem=<type>
which does not match the parent QuickGrid's item type.
Ensure the GridSort type parameter matches the grid's item type.

Fixes #56437

@BharatRamsf3693 BharatRamsf3693 requested a review from a team as a code owner June 25, 2026 11:38
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @BharatRamsf3693. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

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

This PR improves QuickGrid’s diagnostics when a column ends up being constructed with a different TGridItem than its parent QuickGrid<TGridItem> (commonly via a mismatched GridSort<TSortItem>), by cascading the grid’s item Type to columns and validating during column registration. It also adds an E2E page and tests covering several mismatch scenarios.

Changes:

  • Cascade the grid item type (typeof(TGridItem)) from QuickGrid to descendant columns.
  • Validate column TGridItem vs. grid item type and throw a clearer InvalidOperationException on mismatch.
  • Add a dedicated test page and E2E tests to assert the improved error output in interactive server mode.

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/Components/test/testassets/Components.TestServer/RazorComponents/Pages/QuickGrid/QuickGridTypeMismatch.razor Adds a test page exercising multiple QuickGrid/column type mismatch scenarios via error boundaries.
src/Components/test/E2ETest/Tests/QuickGridInteractiveTest.cs Adds E2E assertions verifying the improved mismatch diagnostics are surfaced to developers.
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor Cascades the grid item Type to descendants using a named CascadingValue.
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor.cs Adds a named cascading parameter to receive the grid’s item Type.
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor Implements the type mismatch validation and throws a clearer exception.

@BharatRamsf3693

Copy link
Copy Markdown
Author

All review comments have been addressed, and the implementation has been further optimized.

@ilonatommy

Copy link
Copy Markdown
Member

All review comments have been addressed

There is a "resolve conversation" button you can use under each review comment to mark that.

@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Jun 26, 2026

@ilonatommy ilonatommy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Public API changes from community PRs are not planned anymore for this release. We can take only internal fixes, otherwise it will wait for .net12.

}
}
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Run git checkout main on this file.

{
string displayName = string.IsNullOrWhiteSpace(Title) ? "(unnamed)" : Title;
throw new InvalidOperationException($"Column '{displayName}' has TGridItem={typeof(TGridItem).FullName} which does not match the parent QuickGrid's item type. Ensure the GridSort type parameter matches the grid's item type.");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did we move the check from base to TemplateColumn? In QuickGrid we support custom columns. This fix adds better diagnostics only for blazor columns, custom ones will still hit the original issue. E.g. add test for PropertyColumn to see that it will have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve diagnostics on incorrect GridSort specification in QuickGrid

3 participants