Elegantly Visualize Hierarchical Data with WinUI DataGrid's Master-Details View!
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (181).NET Core  (28).NET MAUI  (227)Angular  (113)ASP.NET  (49)ASP.NET Core  (81)ASP.NET MVC  (87)Azure  (42)Black Friday Deal  (1)Blazor  (236)BoldSign  (14)DocIO  (24)Essential JS 2  (110)Essential Studio  (200)File Formats  (73)Flutter  (136)JavaScript  (226)Microsoft  (122)PDF  (83)Python  (1)React  (105)Streamlit  (1)Succinctly series  (131)Syncfusion  (964)TypeScript  (33)Uno Platform  (3)UWP  (3)Vue  (46)Webinar  (53)Windows Forms  (59)WinUI  (72)WPF  (163)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (11)Business intelligence  (55)Button  (4)C#  (164)Chart  (147)Chart of the week  (58)Cloud  (15)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (73)Development  (681)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (43)Extensions  (23)File Manager  (7)Gantt  (21)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (522)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (45)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (406)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (628)What's new  (341)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Elegantly Visualize Hierarchical Data with WinUI DataGrid's Master-Details View!

Elegantly Visualize Hierarchical Data with WinUI DataGrid’s Master-Details View!

TL;DR: Are you seeking a tool to visualize your complex hierarchical data? Dive into the WinUI DataGrid’s master details view! Learn to represent hierarchical data and generate relations for nested tables effortlessly with code examples, simplifying your data visualization process!

The Syncfusion WinUI DataGrid is used to display and manipulate tabular data. Its rich feature set includes data binding, editing, sorting, filtering, grouping, and more. Additionally, it has been optimized to handle large datasets and real-time updates efficiently.

In this blog, we will explore the master-details view in the WinUI DataGrid control with code examples.

Note: Before proceeding, refer to the documentation on getting started with WinUI DataGrid.

Master-details view in WinUI DataGrid: An overview

The WinUI DataGrid supports hierarchical data representation (nested grid) through the master-details view. This view allows nested tables (DetailsViewDataGrid) to be expanded or collapsed using an expander in a row or programmatically. The number of nested tables is not limited.

Generating master-details view

The master-details view can automatically generate relations for properties of type IEnumerable within the underlying data object. These relations can be generated either automatically or manually for the master details view.

Let’s see how to generate relations with code examples.

Auto-generating relations

By enabling the AutoGenerateRelations property, the WinUI DataGrid will automatically create relations and inner relations for the IEnumerable property types in the data object.

Refer to the following code example.

<dataGrid:SfDataGrid DataContext="{StaticResource orderInfoViewModel}"
                     x:Name="sfDataGrid"
                     ColumnWidthMode="Auto"
                     AutoGenerateColumns="True"
                     AutoGenerateRelations="True"
                     ItemsSource="{Binding OrdersDetails}"
                     AllowEditing="True"
                     GridLinesVisibility="Both">
</dataGrid:SfDataGrid>

Creating relations manually

You can also manually generate the master-details view relation using the DetailsViewDefinition property when the AutoGenerateRelations property is disabled.

To define relations, create a GridViewDefinition class and assign the name of the Ienumerable type property from the data object to the ViewDefinition.RelationalColumn property. Then, add the GridViewDefinition class you created to the DetailsViewDefinition property of the DataGrid.

Refer to the following code example.

<dataGrid:SfDataGrid DataContext="{StaticResource orderInfoViewModel}"
                     x:Name="sfDataGrid"
                     ColumnWidthMode="Auto"
                     AutoGenerateColumns="True"
                     HideEmptyGridViewDefinition="True"      
                     ItemsSource="{Binding OrdersDetails}"
                     AllowEditing="True"
                     GridLinesVisibility="Both">
 <dataGrid:SfDataGrid.DetailsViewDefinition>
  <dataGrid:GridViewDefinition RelationalColumn="OrderDetails">
   <dataGrid:GridViewDefinition.DataGrid>
    <dataGrid:SfDataGrid 
                        x:Name="FirstDetailsViewGrid" 
                        AllowEditing="True"
                        GridLinesVisibility="Both"
                        AutoGenerateColumns="True">
    </dataGrid:SfDataGrid>
   </dataGrid:GridViewDefinition.DataGrid>
  </dataGrid:GridViewDefinition>
 </dataGrid:SfDataGrid.DetailsViewDefinition>
</dataGrid:SfDataGrid>

Hiding empty relations

By default, the expander for all the parent records is visible, allowing even empty data to be expanded.

Enable the HideEmptyGridViewDefinition property to prevent empty relations from being displayed and to hide the expander when the corresponding relational column has an empty collection or is null.

Refer to the following code example.

<dataGrid:SfDataGrid DataContext="{StaticResource orderInfoViewModel}"
                     x:Name="sfDataGrid"
                     ColumnWidthMode="Auto"
                     AutoGenerateColumns="True"
                     AutoGenerateRelations="True"
                     HideEmptyGridViewDefinition="True"      
                     ItemsSource="{Binding OrdersDetails}"
                     AllowEditing="True"
                     GridLinesVisibility="Both">
</dataGrid:SfDataGrid>

Refer to the following image.

Hiding expander for empty relation rows in WinUI DataGrid
Hiding expander for empty relation rows in WinUI DataGrid

Enhancing data visualization with master-details view in WinUI DataGrid

Let’s see how to visualize a huge volume of order details with the master-details view in the WinUI DataGrid.

Here, each task (row) has a child grid beneath it that displays a list of orders associated with that task. The parent grid is a DataGrid, and expanding a parent row reveals its child rows. The nested grid UI displays both parent and child rows in a structured grid format, providing additional information about the rows.

The relational column and the grid columns to be shown in the nested grid UI are defined in the following code example.

<dataGrid:SfDataGrid DataContext="{StaticResource orderInfoViewModel}"
                     x:Name="sfDataGrid"
                     ColumnWidthMode="Auto"
                     AutoGenerateColumns="False"
                     HideEmptyGridViewDefinition="True"      
                     ItemsSource="{Binding OrdersDetails}"
                     AllowEditing="True"
                     GridLinesVisibility="Both">
 <dataGrid:SfDataGrid.DetailsViewDefinition>
  <dataGrid:GridViewDefinition RelationalColumn="OrderDetails">
   <dataGrid:GridViewDefinition.DataGrid>
    <dataGrid:SfDataGrid 
                        x:Name="FirstDetailsViewGrid" 
                        AllowEditing="True"
                        GridLinesVisibility="Both"
                        AutoGenerateColumns="false">
     <dataGrid:SfDataGrid.Columns>
      <dataGrid:GridNumericColumn HeaderText="Order ID" MappingName="OrderID" TextAlignment="Right"/>
      <dataGrid:GridTextColumn HeaderText="Customer ID" MappingName="CustomerID" />
       <dataGrid:GridNumericColumn HeaderText="Product ID"   MappingName="ProductID"  TextAlignment="Right" />
       <dataGrid:GridNumericColumn MappingName="Quantity" TextAlignment="Right" />
       <dataGrid:GridNumericColumn MappingName="Discount"  TextAlignment="Right" DisplayNumberFormat="P"/>
       <dataGrid:GridDateColumn MappingName="OrderDate" GroupMode="Display" HeaderText="Order Date" TextAlignment="Right" />
      </dataGrid:SfDataGrid.Columns>
     </dataGrid:SfDataGrid>
    </dataGrid:GridViewDefinition.DataGrid>
   </dataGrid:GridViewDefinition>
  </dataGrid:SfDataGrid.DetailsViewDefinition>
  <dataGrid:SfDataGrid.Columns>
   <dataGrid:GridNumericColumn HeaderText="Order ID" MappingName="OrderID" TextAlignment="Right"/>
   <dataGrid:GridTextColumn HeaderText="Customer ID" MappingName="CustomerID" />
   <dataGrid:GridDateColumn GroupMode="Display" HeaderText="Shipping Date" MappingName="ShippedDate" TextAlignment="Right" />
   <dataGrid:GridTextColumn HeaderText="Product Name" MappingName="ProductName" />
   <dataGrid:GridTextColumn HeaderText="Company Name" MappingName="CompanyName"/>
   <dataGrid:GridNumericColumn MappingName="Quantity" />
   <dataGrid:GridTextColumn HeaderText="Ship Country" MappingName="ShipAddress" />
   <dataGrid:GridNumericColumn MappingName="Freight" NumberFormatter="{Binding SystemCurrency,Source={StaticResource orderInfoViewModel}}" TextAlignment="Right" />
  </dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid>

Refer to the following output GIF image.

Visualizing the hierarchical data using the master-details view (Nested grid UI) in WinUI DataGrid
Visualizing the hierarchical data using the master-details view (Nested grid UI) in WinUI DataGrid

GitHub reference

For more details, refer to the master-details view (Nested Grid UI) in the WinUI DataGrid project on GitHub.

Conclusion

Thanks for reading! In this blog, we’ve explored how to enhance data visualization using the master details view in the Syncfusion WinUI DataGrid. We encourage you to try these steps and share your feedback in the comments below.

Existing customers can download the new version of Essential Studio for WinUI on the License and Downloads page. If you are not a Syncfusion customer, try our 30-day free trial to experience our incredible features. 

You can also contact us through our support forumssupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed