FlexGrid Row Details for Blazor
FlexGrid for Blazor can show tabular data in an Excel-like grid. It supports many features for displaying information effectively. One feature is RowDetails; this provides flexibility when demonstrating additional data on each record in a detail section using a custom template. This template can contain any HTML or a Blazor control.
In this article, we will discuss two ways to display additional information using RowDetails inside FlexGrid.
How to Use HTML in RowDetails
Step 1: Create the Blazor Web Assembly Project
Create a Blazor Web Assembly project in VS2019.
Step 2: Adding Style Resource Entries
Open Index.html from under wwwroot and add the following style resource entries within the head tag:
Add the following scripts within body tags:
Step 3: Adding FlexGrid
Suppose we have a Customer class with Id, FirstName, LastName, Country, City, Address, and PostalCode public properties. We wish to show Country, City, Address, and PostalCode inside each row's detail section. To configure the grid to display such data, open the Index. razor page and clear all code except the top @page directive. Let's add a FlexGrid control and configure it to show Id, FirstName, and LastName.
Step 4: FlexGrid Configuration
Now, we can add a FlexgridDetailProvider to display Country, City, Address, and PostalCode. To get started, add a FlexGridBehaviors tag and inside that add a FlexgridDetailProvider. In the FlexgridDetailProvider, we can define a template to show detail data. Here is the complete FlexGrid configuration:
Note TItem is set to Customer, where the detail binding information is extracted. This action enables the data-binding of detail elements using the context and respective property names.
Step 5: Create the Customer's Data Collection
In this step, we will add code to create the customer's data collection to which the grid is bound:
That is all we need to configure FlexGrid to use RowDetails.
How to Use FlexGrid in RowDetails
The second way to use row details is to display a control inside RowDetails. Here we will discuss how to use FlexGrid. We will learn how to use nested FlexGrid to display master-detail data.
Step 1: Fetching Data from a REST API
Add another Page to the project. In the @Code section, we will fetch Customers and Orders data from a REST API and use LINQ to create a relational data collection based on the CustomerID column:
Step 2: Declaring FlexGrid
Now we can declare FlexGrid to show Customer data and configure the row detail with a second FlexGrid to display related Orders:
The TItem for FlexGridDetailProvider is the CustomerWithOrders type, and the context makes the Orders to detail FlexGrid available.
What’s Next: Improving Simple Data Scenarios
The current row details implementation helps with simple data scenarios. To show nested details on demand, the FlexGridDetailProvider would need an async API and additional information about the parent row for related data to be shown in detail. To support such cases, we are working on adding an API for the 2020v3 release this year.
Check out the Blazor demo to see FlexGrid and all other controls in action.