-
Notifications
You must be signed in to change notification settings - Fork 462
[dev-v5][DataGrid] Add Hierarchical DataGrid functionality #4482
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5dd1114
Add the HierarchicalGridItem basis and example
vnbaaij 67ce127
- Add example with more than 1 level
vnbaaij f601886
- Add more tests and update veriefied files
vnbaaij 8379b62
Update docs
vnbaaij 82d522b
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/hierarchical-grid-item
vnbaaij bd4c811
- Add checks and tests so that only 1 HerarchicalToggle can exist and…
vnbaaij 70c4698
Process review comments
vnbaaij ba2b182
Typo
vnbaaij 8ccdad0
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/hierarchical-grid-item
vnbaaij fe7a9a1
Merge branch 'users/vnbaaij/dev-v5/hierarchical-grid-item' of https:/…
vnbaaij 0aa23ae
Some optimizations for when using the DataGrid in rtl mode
vnbaaij 5c0efc5
Store
vnbaaij c05ce32
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/hierarchical-grid-item
vnbaaij 8af6147
Merge branch 'users/vnbaaij/dev-v5/hierarchical-grid-item' of https:/…
vnbaaij 91b39cc
- Use addEventListener on gridElement instead of document
vnbaaij cbe7f60
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/hierarchical-grid-item
vnbaaij 4426fc7
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/hierarchical-grid-item
dvoituron 7594d25
merge
vnbaaij 78e1fbe
Merge branch 'users/vnbaaij/dev-v5/hierarchical-grid-item' of https:/…
vnbaaij 8fd2158
Fix script. Final tweaks
vnbaaij 0b2a078
Merge branch 'dev-v5' into users/vnbaaij/dev-v5/hierarchical-grid-item
vnbaaij 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
59 changes: 59 additions & 0 deletions
59
...luentUI.Demo.Client/Documentation/Components/DataGrid/Examples/DataGridHierarchical.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,59 @@ | ||
| @using static FluentUI.Demo.SampleData.Olympics2024 | ||
|
|
||
| <FluentDataGrid Items="@items.Where(i => !i.IsHidden).AsQueryable()" ShowHover="true" ResizableColumns="true"> | ||
| <TemplateColumn Title="Name" HierarchicalToggle="true"> | ||
| @if (context.Item.ContinentCode != null) | ||
| { | ||
| <img class="flag" src="@(context.Item.Flag())" alt="Flag of @(context.Item.Code)" /> | ||
| } | ||
| @context.Item.Name | ||
| </TemplateColumn> | ||
| <PropertyColumn Title="Gold" Property="@(i => i.Item.Medals.Gold)" /> | ||
| <PropertyColumn Title="Silver" Property="@(i => i.Item.Medals.Silver)" Align="DataGridCellAlignment.Center" /> | ||
| <PropertyColumn Title="Bronze" Property="@(i => i.Item.Medals.Bronze)" Align="DataGridCellAlignment.Center" /> | ||
| <PropertyColumn Title="Total" Property="@(i => i.Item.Medals.Total)" Align="DataGridCellAlignment.End" /> | ||
|
|
||
| </FluentDataGrid> | ||
|
|
||
| @code { | ||
| List<OlympicGridItem> items = new(); | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| foreach (var continent in Continents) | ||
| { | ||
| var countries = Countries.Where(c => c.ContinentCode == continent.Code).OrderByDescending(c => c.Medals.Total); | ||
|
|
||
| var continentItem = new OlympicGridItem | ||
| { | ||
| Item = continent with | ||
| { | ||
| Medals = new Medals( | ||
| Gold: countries.Sum(c => c.Medals.Gold), | ||
| Silver: countries.Sum(c => c.Medals.Silver), | ||
| Bronze: countries.Sum(c => c.Medals.Bronze) | ||
| ) | ||
| }, | ||
| IsCollapsed = true | ||
| }; | ||
|
|
||
| items.Add(continentItem); | ||
|
|
||
| foreach (var country in countries) | ||
| { | ||
| var countryItem = new OlympicGridItem | ||
| { | ||
| Item = country, | ||
| Depth = 1, | ||
| IsHidden = true | ||
| }; | ||
| continentItem.Children.Add(countryItem); | ||
| items.Add(countryItem); | ||
| } | ||
vnbaaij marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| public class OlympicGridItem : HierarchicalGridItem<Country, OlympicGridItem> | ||
| { | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
...tUI.Demo.Client/Documentation/Components/DataGrid/Examples/DataGridHierarchical.razor.css
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,12 @@ | ||
| :root { | ||
| --datagrid-hover-color: lightyellow; | ||
| } | ||
|
|
||
| .fluent-data-grid { | ||
| --fluent-data-grid-resize-handle-color: var(--colorNeutralStencil1) !important; | ||
| } | ||
|
|
||
| .flag { | ||
| height: 1rem; | ||
| border: 1px solid var(--colorNeutralBackground3); | ||
| } |
18 changes: 18 additions & 0 deletions
18
...Demo.Client/Documentation/Components/DataGrid/Examples/DataGridHierarchicalOrgChart.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,18 @@ | ||
| @using FluentUI.Demo.SampleData | ||
| @using static FluentUI.Demo.SampleData.People | ||
|
|
||
| <FluentButton Appearance="ButtonAppearance.Primary" IconStart="@(ceoItem?.IsCollapsed == true ? new Icons.Regular.Size16.Add() : new Icons.Regular.Size16.Subtract())" | ||
| OnClick="@ToggleCEO"> | ||
| @(ceoItem?.IsCollapsed == true ? "Expand" : "Collapse") CEO | ||
| </FluentButton> | ||
|
|
||
| <FluentDataGrid Items="@items.Where(i => !i.IsHidden).AsQueryable()" ResizableColumns="true"> | ||
| <TemplateColumn Title="Name" HierarchicalToggle="true"> | ||
| @(context.Item.FirstName + " " + context.Item.LastName) | ||
| </TemplateColumn> | ||
| <PropertyColumn Title="Job Title" Property="@(i => i.Item.JobTitle)" /> | ||
| <PropertyColumn Title="Department" Property="@(i => i.Item.Department)" /> | ||
| <PropertyColumn Title="Location" Property="@(i => i.Item.Location)" /> | ||
| </FluentDataGrid> | ||
|
|
||
|
|
58 changes: 58 additions & 0 deletions
58
...o.Client/Documentation/Components/DataGrid/Examples/DataGridHierarchicalOrgChart.razor.cs
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 @@ | ||
| // ------------------------------------------------------------------------ | ||
| // This file is licensed to you under the MIT License. | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| using Microsoft.FluentUI.AspNetCore.Components; | ||
| using static FluentUI.Demo.SampleData.People; | ||
|
|
||
| namespace FluentUI.Demo.Client.Documentation.Components.DataGrid.Examples; | ||
|
|
||
| public partial class DataGridHierarchicalOrgChart | ||
| { | ||
| private PersonGridItem? ceoItem; | ||
| private readonly List<PersonGridItem> items = []; | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| var allPeople = GeneratePersons(30).ToList(); | ||
|
|
||
| // Level 0: CEO/Manager | ||
| var ceo = allPeople[0] with { FirstName = "Mads", LastName = "Torgersen", JobTitle = "CEO", Department = "Executive" }; | ||
| ceoItem = new PersonGridItem | ||
| { | ||
| Item = ceo, | ||
| IsCollapsed = false | ||
| }; | ||
| items.Add(ceoItem); | ||
|
|
||
| // ... existing code ... | ||
| for (var i = 1; i <= 3; i++) | ||
| { | ||
| var manager = allPeople[i] with { JobTitle = "Director", Department = "Engineering" }; | ||
| var managerItem = new PersonGridItem { Item = manager, Depth = 1, IsCollapsed = i != 2 }; | ||
| ceoItem.Children.Add(managerItem); | ||
| items.Add(managerItem); | ||
|
|
||
| // Level 2: Employees | ||
| for (var j = 0; j < 4; j++) | ||
| { | ||
| var employee = allPeople[4 + (i - 1) * 4 + j]; | ||
| var employeeItem = new PersonGridItem { Item = employee, Depth = 2, IsHidden = i != 2 }; | ||
| managerItem.Children.Add(employeeItem); | ||
| items.Add(employeeItem); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void ToggleCEO() | ||
| { | ||
| if (ceoItem is not null) | ||
| { | ||
| ceoItem.IsCollapsed = !ceoItem.IsCollapsed; | ||
| } | ||
| } | ||
|
|
||
| public class PersonGridItem : HierarchicalGridItem<Person, PersonGridItem> | ||
| { | ||
| } | ||
| } |
4 changes: 2 additions & 2 deletions
4
...FluentUI.Demo.Client/Documentation/Components/DataGrid/Examples/DataGridTypical.razor.css
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
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
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
26 changes: 26 additions & 0 deletions
26
...Demo.Client/Documentation/Components/DataGrid/Pages/DataGridHierarchicalPage.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,26 @@ | ||
| --- | ||
vnbaaij marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| title: Hierarchical data | ||
| route: /DataGrid/Hierarchical | ||
| --- | ||
|
|
||
| # Hierarchical data | ||
|
|
||
| ## Single-level hierarchy | ||
|
|
||
| The `FluentDataGrid` supports displaying hierarchical data. | ||
|
|
||
| By using the `HierarchicalGridItem` class (or a class derived from it) as the grid item type, | ||
| you can define parent-child relationships between items. | ||
|
|
||
| Set the `HierarchicalToggle` parameter to `true` on one of the columns to display the expand/collapse button. | ||
|
|
||
| {{ DataGridHierarchical Files=Code:DataGridHierarchical.razor;CSS:DataGridHierarchical.razor.css}} | ||
|
|
||
| ## Multi-level hierarchy | ||
|
|
||
| The hierarchical data grid can display multiple levels of nesting. In this example, we show an organization chart with three levels: CEO, Directors, and Employees. | ||
|
|
||
| This example also shows how to programmatically expand and collapse rows by manually setting the `IsCollapsed` property on a `HierarchicalGridItem` instance. | ||
|
|
||
| {{ DataGridHierarchicalOrgChart Files=Code:DataGridHierarchicalOrgChart.razor}} | ||
|
|
||
Oops, something went wrong.
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.