-
Notifications
You must be signed in to change notification settings - Fork 473
[dev-v5][DataGrid] Add master/detail row expansion #5011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sebguischr
wants to merge
5
commits into
microsoft:dev-v5
Choose a base branch
from
sebguischr:feature/datagrid-master-detail-v5
base: dev-v5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62aff69
[DataGrid] Add master/detail row expansion
sebguischr f8249d5
[DataGrid] Fix RowDetails CSS for dev-v5's unscoped stylesheet model
sebguischr af9aaec
[DataGrid] Address review feedback on RowDetails
sebguischr cb67cfa
[DataGrid] Exclude row-details-row from the ShowHover highlight
sebguischr 0a419eb
[DataGrid] Add custom-content RowDetails example
sebguischr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...luentUI.Demo.Client/Documentation/Components/DataGrid/Examples/DataGridMasterDetail.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <style> | ||
| .row-details-cell { | ||
| padding: 0.5rem 1rem 1rem 2.5rem; | ||
| background: var(--colorNeutralBackground2); | ||
| } | ||
| </style> | ||
|
|
||
| <FluentDataGrid Items="@customers" ShowHover="true"> | ||
| <ChildContent> | ||
| <PropertyColumn Title="Customer" Property="@(c => c.Name)" Sortable="true" /> | ||
| <PropertyColumn Title="City" Property="@(c => c.City)" Sortable="true" /> | ||
| <PropertyColumn Title="Orders" Property="@(c => OrdersOf(c.Id).Count())" Align="DataGridCellAlignment.End" /> | ||
| <PropertyColumn Title="Total amount" Property="@(c => OrdersOf(c.Id).Sum(o => o.Amount))" Format="c" Align="DataGridCellAlignment.End" /> | ||
| </ChildContent> | ||
| <RowDetails Context="customer"> | ||
| <h5 style="margin: 0 0 0.5rem 0;">Orders of @customer.Name</h5> | ||
| <FluentDataGrid Items="@OrdersOf(customer.Id)" ShowHover="true"> | ||
| <PropertyColumn Title="Order #" Property="@(o => o.OrderNumber)" /> | ||
| <PropertyColumn Title="Date" Property="@(o => o.OrderDate)" Format="yyyy-MM-dd" Sortable="true" InitialSortDirection="DataGridSortDirection.Descending" IsDefaultSortColumn="true" /> | ||
| <PropertyColumn Title="Amount" Property="@(o => o.Amount)" Format="c" Align="DataGridCellAlignment.End" Sortable="true" /> | ||
| <TemplateColumn Title="Status"> | ||
| <FluentBadge Color="@(context.Status == "Delivered" ? BadgeColor.Success : BadgeColor.Subtle)"> | ||
| @context.Status | ||
| </FluentBadge> | ||
| </TemplateColumn> | ||
| </FluentDataGrid> | ||
| </RowDetails> | ||
| </FluentDataGrid> | ||
|
|
||
| @code { | ||
| private record Customer(int Id, string Name, string City); | ||
| private record Order(string OrderNumber, int CustomerId, DateTime OrderDate, decimal Amount, string Status); | ||
|
|
||
| private IQueryable<Customer> customers = new List<Customer> | ||
| { | ||
| new(1, "Contoso Ltd.", "Seattle"), | ||
| new(2, "Fabrikam, Inc.", "Paris"), | ||
| new(3, "Northwind Traders", "London"), | ||
| new(4, "Adventure Works", "Brussels"), | ||
| }.AsQueryable(); | ||
|
|
||
| private List<Order> orders = new() | ||
| { | ||
| new("ORD-1001", 1, new DateTime(2026, 5, 12), 1250.00m, "Delivered"), | ||
| new("ORD-1002", 1, new DateTime(2026, 6, 3), 480.50m, "Shipped"), | ||
| new("ORD-1003", 1, new DateTime(2026, 6, 28), 90.00m, "Pending"), | ||
| new("ORD-1004", 2, new DateTime(2026, 4, 21), 3200.00m, "Delivered"), | ||
| new("ORD-1005", 2, new DateTime(2026, 6, 15), 150.75m, "Cancelled"), | ||
| new("ORD-1006", 3, new DateTime(2026, 5, 30), 780.25m, "Delivered"), | ||
| new("ORD-1007", 3, new DateTime(2026, 6, 10), 2100.00m, "Shipped"), | ||
| new("ORD-1008", 3, new DateTime(2026, 7, 1), 55.99m, "Pending"), | ||
| new("ORD-1009", 4, new DateTime(2026, 6, 22), 640.00m, "Shipped"), | ||
| }; | ||
|
|
||
| // The child grid is filtered with the master row's item (the customer) | ||
| private IQueryable<Order> OrdersOf(int customerId) | ||
| => orders.Where(o => o.CustomerId == customerId).AsQueryable(); | ||
| } |
76 changes: 76 additions & 0 deletions
76
...I.Demo.Client/Documentation/Components/DataGrid/Examples/DataGridMasterDetailCustom.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| ο»Ώ<style> | ||
| .custom-detail .row-details-cell { | ||
| background: var(--colorNeutralBackground2); | ||
| } | ||
|
|
||
| .custom-detail .detail-card { | ||
| max-width: 32rem; | ||
| margin: 1rem 0 1rem 1.5rem; | ||
| padding: 1.25rem 1.5rem; | ||
| } | ||
|
|
||
| .custom-detail .detail-label { | ||
| color: var(--colorNeutralForeground3); | ||
| min-width: 5rem; | ||
| } | ||
|
|
||
| .custom-detail .detail-email { | ||
| color: var(--colorBrandForegroundLink); | ||
| } | ||
| </style> | ||
|
|
||
| <div class="custom-detail"> | ||
| <FluentDataGrid Items="@customers" ShowHover="true"> | ||
| <ChildContent> | ||
| <PropertyColumn Title="Customer" Property="@(c => c.Name)" Sortable="true" /> | ||
| <PropertyColumn Title="City" Property="@(c => c.City)" Sortable="true" /> | ||
| <TemplateColumn Title="Status"> | ||
| <FluentBadge Color="@(context.IsActive ? BadgeColor.Success : BadgeColor.Subtle)"> | ||
| @(context.IsActive ? "Active" : "Inactive") | ||
| </FluentBadge> | ||
| </TemplateColumn> | ||
| </ChildContent> | ||
| <RowDetails Context="customer"> | ||
| <FluentCard Class="detail-card"> | ||
| <FluentStack Orientation="Orientation.Vertical" VerticalGap="12"> | ||
| <h5 style="margin: 0;">@customer.Name</h5> | ||
|
|
||
| <FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center" HorizontalGap="8"> | ||
| <FluentIcon Value="@(new Icons.Regular.Size20.Location())" Color="Color.Default" /> | ||
| <span class="detail-label">City</span> | ||
| <span>@customer.City</span> | ||
| </FluentStack> | ||
|
|
||
| <FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center" HorizontalGap="8"> | ||
| <FluentIcon Value="@(new Icons.Regular.Size20.Mail())" Color="Color.Default" /> | ||
| <span class="detail-label">Email</span> | ||
| <a class="detail-email" href="@($"mailto:{customer.Email}")">@customer.Email</a> | ||
| </FluentStack> | ||
|
|
||
| <FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center" HorizontalGap="8"> | ||
| <FluentIcon Value="@(new Icons.Regular.Size20.Phone())" Color="Color.Default" /> | ||
| <span class="detail-label">Phone</span> | ||
| <span>@customer.Phone</span> | ||
| </FluentStack> | ||
|
|
||
| <FluentStack Orientation="Orientation.Vertical" VerticalGap="4"> | ||
| <span class="detail-label">Satisfaction</span> | ||
| <FluentProgressBar Min="0" Max="100" Value="@customer.Satisfaction" Width="200px" /> | ||
| </FluentStack> | ||
| </FluentStack> | ||
| </FluentCard> | ||
| </RowDetails> | ||
| </FluentDataGrid> | ||
| </div> | ||
|
|
||
| @code { | ||
| private record Customer(int Id, string Name, string City, string Email, string Phone, int Satisfaction, bool IsActive); | ||
|
|
||
| private IQueryable<Customer> customers = new List<Customer> | ||
| { | ||
| new(1, "Contoso Ltd.", "Seattle", "contact@contoso.com", "+1 206 555 0100", 92, true), | ||
| new(2, "Fabrikam, Inc.", "Paris", "hello@fabrikam.com", "+33 1 55 00 12 00", 78, true), | ||
| new(3, "Northwind Traders", "London", "sales@northwind.com", "+44 20 7946 0000", 64, false), | ||
| new(4, "Adventure Works", "Brussels", "info@adventure-works.com", "+32 2 555 01 23", 85, true), | ||
| }.AsQueryable(); | ||
| } |
76 changes: 76 additions & 0 deletions
76
...emo.Client/Documentation/Components/DataGrid/Examples/DataGridMasterDetailTwoLevels.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <style> | ||
| .two-levels .row-details-cell { | ||
| padding: 0.5rem 1rem 1rem 2.5rem; | ||
| background: var(--colorNeutralBackground2); | ||
| } | ||
|
|
||
| /* Second level of details, nested inside the first one */ | ||
| .two-levels .row-details-cell .row-details-cell { | ||
| background: var(--colorNeutralBackground3); | ||
| } | ||
| </style> | ||
|
|
||
| <div class="two-levels"> | ||
| <FluentDataGrid Items="@customers" ShowHover="true"> | ||
| <ChildContent> | ||
| <PropertyColumn Title="Customer" Property="@(c => c.Name)" Sortable="true" /> | ||
| <PropertyColumn Title="City" Property="@(c => c.City)" Sortable="true" /> | ||
| <PropertyColumn Title="Orders" Property="@(c => OrdersOf(c.Id).Count())" Align="DataGridCellAlignment.End" /> | ||
| </ChildContent> | ||
| <RowDetails Context="customer"> | ||
| <h5 style="margin: 0 0 0.5rem 0;">Orders of @customer.Name</h5> | ||
| <FluentDataGrid Items="@OrdersOf(customer.Id)" ShowHover="true"> | ||
| <ChildContent> | ||
| <PropertyColumn Title="Order #" Property="@(o => o.OrderNumber)" /> | ||
| <PropertyColumn Title="Date" Property="@(o => o.OrderDate)" Format="yyyy-MM-dd" Sortable="true" InitialSortDirection="DataGridSortDirection.Descending" IsDefaultSortColumn="true" /> | ||
| <PropertyColumn Title="Amount" Property="@(o => LinesOf(o.OrderNumber).Sum(l => l.Quantity * l.UnitPrice))" Format="c" Align="DataGridCellAlignment.End" /> | ||
| </ChildContent> | ||
| <RowDetails Context="order"> | ||
| <h5 style="margin: 0 0 0.5rem 0;">Lines of order @order.OrderNumber</h5> | ||
| <FluentDataGrid Items="@LinesOf(order.OrderNumber)" ShowHover="true"> | ||
| <PropertyColumn Title="Product" Property="@(l => l.Product)" /> | ||
| <PropertyColumn Title="Quantity" Property="@(l => l.Quantity)" Align="DataGridCellAlignment.End" /> | ||
| <PropertyColumn Title="Unit price" Property="@(l => l.UnitPrice)" Format="c" Align="DataGridCellAlignment.End" /> | ||
| <PropertyColumn Title="Line total" Property="@(l => l.Quantity * l.UnitPrice)" Format="c" Align="DataGridCellAlignment.End" /> | ||
| </FluentDataGrid> | ||
| </RowDetails> | ||
| </FluentDataGrid> | ||
| </RowDetails> | ||
| </FluentDataGrid> | ||
| </div> | ||
|
|
||
| @code { | ||
| private record Customer(int Id, string Name, string City); | ||
| private record Order(string OrderNumber, int CustomerId, DateTime OrderDate); | ||
| private record OrderLine(string OrderNumber, string Product, int Quantity, decimal UnitPrice); | ||
|
|
||
| private IQueryable<Customer> customers = new List<Customer> | ||
| { | ||
| new(1, "Contoso Ltd.", "Seattle"), | ||
| new(2, "Fabrikam, Inc.", "Paris"), | ||
| }.AsQueryable(); | ||
|
|
||
| private List<Order> orders = new() | ||
| { | ||
| new("ORD-1001", 1, new DateTime(2026, 5, 12)), | ||
| new("ORD-1002", 1, new DateTime(2026, 6, 3)), | ||
| new("ORD-1004", 2, new DateTime(2026, 4, 21)), | ||
| }; | ||
|
|
||
| private List<OrderLine> lines = new() | ||
| { | ||
| new("ORD-1001", "Standing desk", 2, 450.00m), | ||
| new("ORD-1001", "Office chair", 2, 175.00m), | ||
| new("ORD-1002", "Monitor 27\"", 1, 320.50m), | ||
| new("ORD-1002", "HDMI cable", 4, 40.00m), | ||
| new("ORD-1004", "Laptop docking station", 10, 220.00m), | ||
| new("ORD-1004", "Wireless keyboard", 10, 100.00m), | ||
| }; | ||
|
|
||
| // Each level filters its child grid with its own row item | ||
| private IQueryable<Order> OrdersOf(int customerId) | ||
| => orders.Where(o => o.CustomerId == customerId).AsQueryable(); | ||
|
|
||
| private IQueryable<OrderLine> LinesOf(string orderNumber) | ||
| => lines.Where(l => l.OrderNumber == orderNumber).AsQueryable(); | ||
| } |
48 changes: 48 additions & 0 deletions
48
...Demo.Client/Documentation/Components/DataGrid/Pages/DataGridMasterDetailPage.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| title: Master / Detail | ||
| route: /DataGrid/MasterDetail | ||
| --- | ||
|
|
||
| # Master / Detail | ||
|
|
||
| The `FluentDataGrid` supports a master/detail view. Set the `RowDetails` template parameter to make each row | ||
| expandable through a chevron button shown in the first column. The template content is rendered in an extra row, | ||
| spanning all columns, directly below the expanded row. | ||
|
|
||
| The template's `context` is the master row's item, so you can place a child `FluentDataGrid` inside it and filter | ||
| its items based on the master row. In this example, expanding a customer shows a child grid with that customer's | ||
| orders. | ||
|
|
||
| Unlike the [hierarchical view](/DataGrid/Hierarchical) β where parent and child rows share the same item type and | ||
| the same columns within a single grid β the master/detail view displays data of a completely different structure: | ||
| the child grid defines its own columns, sorting and content, and is simply filtered by the master row's item. | ||
|
|
||
| Rows can also be expanded and collapsed programmatically with the `ToggleRowDetailsAsync`, `ExpandRowDetailsAsync`, | ||
| `CollapseRowDetailsAsync`, `ExpandAllRowDetailsAsync` and `CollapseAllRowDetailsAsync` methods. The | ||
| `OnRowDetailsToggle` event callback is raised for every row whose expansion state actually changes β including once | ||
| per affected row when using `ExpandAllRowDetailsAsync`/`CollapseAllRowDetailsAsync` β but not for rows that were | ||
| already in the requested state. | ||
|
|
||
| *Note: `RowDetails` cannot be combined with `Virtualize`.* | ||
|
|
||
| {{ DataGridMasterDetail Files=Code:DataGridMasterDetail.razor }} | ||
|
|
||
| ## Any content as detail | ||
|
|
||
| The detail template is not limited to a child `FluentDataGrid`: it can host any content. Because the template's | ||
| `context` is the master row's item, you can build a fully custom detail panel β cards, stacks, icons, links, | ||
| progress bars, buttons or any other component β bound to that item. In this example, expanding a customer shows a | ||
| contact card built from standard Fluent components instead of a nested grid. | ||
|
|
||
| {{ DataGridMasterDetailCustom Files=Code:DataGridMasterDetailCustom.razor }} | ||
|
|
||
| ## Two levels of detail | ||
|
|
||
| Since the detail template can contain any content, a child `FluentDataGrid` can itself define a `RowDetails` | ||
| template, giving as many nested levels as needed. In this example, expanding a customer shows its orders, and | ||
| expanding an order shows its order lines. | ||
|
|
||
| Each level filters its own child grid with its own row item (the `Context` of each template is named explicitly β | ||
| `customer`, then `order` β to avoid ambiguity between the nested templates). | ||
|
|
||
| {{ DataGridMasterDetailTwoLevels Files=Code:DataGridMasterDetailTwoLevels.razor }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.