Blazor Hierarchical Grid Summaries
The Ignite UI for Blazor Summaries feature in Blazor Hierarchical Grid functions on a per-column level as group footer. Blazor HierarchicalGrid summaries is powerful feature which enables the user to see column information in a separate container with a predefined set of default summary items, depending on the type of data within the column or by implementing a custom template in the IgbHierarchicalGrid
.
Blazor Hierarchical Grid Summaries Overview Example
[!Note] The summary of the column is a function of all column values, unless filtering is applied, then the summary of the column will be function of the filtered result values
IgbHierarchicalGrid
summaries can also be enabled on a per-column level in Ignite UI for Blazor, which means that you can activate it only for columns that you need. IgbHierarchicalGrid
summaries gives you a predefined set of default summaries, depending on the type of data in the column, so that you can save some time:
For string
and boolean
DataType
, the following function is available:
- Count
For number
, currency
and percent
data types, the following functions are available:
- Count
- Min
- Max
- Average
- Sum
For date
data type, the following functions are available:
- Count
- Earliest
- Latest
All available column data types could be found in the official Column types topic.
IgbHierarchicalGrid
summaries are enabled per-column by setting HasSummary
property to true. It is also important to keep in mind that the summaries for each column are resolved according to the column data type. In the IgbHierarchicalGrid
the default column data type is string
, so if you want number
or date
specific summaries you should specify the DataType
property as number
or date
. Note that the summary values will be displayed localized, according to the grid Locale
and column PipeArgs
.
<IgbHierarchicalGrid AutoGenerate="false" Data="SingersData" Name="hierarchicalGrid" @ref="hierarchicalGrid" Id="hierarchicalGrid" PrimaryKey="ID">
<IgbColumn Field="Artist" HasSummary="true"></IgbColumn>
<IgbColumn Field="Photo" DataType="GridColumnDataType.Image"></IgbColumn>
<IgbColumn Field="Debut" HasSummary="true"></IgbColumn>
<IgbColumn Field="GrammyNominations" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
<IgbColumn Field="GrammyAwards" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
<IgbRowIsland ChildDataKey="Albums" AutoGenerate="false">
<IgbColumn Field="Album" DataType="GridColumnDataType.String"></IgbColumn>
<IgbColumn Field="LaunchDate" DataType="GridColumnDataType.Date"></IgbColumn>
<IgbColumn Field="BillboardReview" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
<IgbColumn Field="USBillboard200" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
</IgbRowIsland>
</IgbHierarchicalGrid>
The other way to enable/disable summaries for a specific column or a list of columns is to use the public method EnableSummaries
/DisableSummaries
of the IgbHierarchicalGrid
.
<IgbHierarchicalGrid AutoGenerate="false" Data="SingersData" Name="hierarchicalGrid" @ref="hierarchicalGrid" Id="hierarchicalGrid" PrimaryKey="ID">
<IgbColumn Field="Artist" HasSummary="true"></IgbColumn>
<IgbColumn Field="Photo" DataType="GridColumnDataType.Image"></IgbColumn>
<IgbColumn Field="Debut" HasSummary="true"></IgbColumn>
<IgbColumn Field="GrammyNominations" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
<IgbColumn Field="GrammyAwards" DataType="GridColumnDataType.Number" HasSummary="true"></IgbColumn>
</IgbHierarchicalGrid>
@code {
public async void DisableSummaries()
{
object[] disabledSummaries = { "GrammyNominations" };
await this.hierarchicalGrid.DisableSummariesAsync(disabledSummaries);
}
}
Custom Hierarchical Grid Summaries
If these functions do not fulfill your requirements you can provide a custom summary for the specific columns.
//In JavaScript
class WebGridDiscontinuedSummary {
operate(data, allData, fieldName) {
const discontinuedData = allData.filter((rec) => rec['Discontinued']).map(r => r[fieldName]);
const result = [];
result.push({
key: 'products',
label: 'Products',
summaryResult: data.length
});
result.push({
key: 'total',
label: 'Total Items',
summaryResult: data.length ? data.reduce((a, b) => +a + +b) : 0
});
result.push({
key: 'discontinued',
label: 'Discontinued Products',
summaryResult: allData.map(r => r['Discontinued']).filter((rec) => rec).length
});
result.push({
key: 'totalDiscontinued',
label: 'Total Discontinued Items',
summaryResult: discontinuedData.length ? discontinuedData.reduce((a, b) => +a + +b) : 0
});
return result;
}
}
As seen in the examples, the base classes expose the Operate
method, so you can choose to get all default summaries and modify the result, or calculate entirely new summary results.
The method returns a list of IgbSummaryResult
.
and take optional parameters for calculating the summaries. See Custom summaries, which access all data section below.
[!Note] In order to calculate the summary row height properly, the Hierarchical Grid needs the
Operate
method to always return an array ofIgbSummaryResult
with the proper length even when the data is empty.
<IgbHierarchicalGrid
AutoGenerate="true"
Name="hierarchicalGrid"
@ref="hierarchicalGrid"
Data="SingersData"
PrimaryKey="ID"
ColumnInitScript="WebHierarchicalGridCustomSummary">
</IgbHierarchicalGrid>
// In Javascript
igRegisterScript("WebHierarchicalGridCustomSummary", (event) => {
if (event.detail.field === "GrammyAwards") {
event.detail.summaries = WebHierarchicalGridSummary;
}
}, false);
Custom summaries, which access all data
Now you can access all Hierarchical Grid data inside the custom column summary. Two additional optional parameters are introduced in the SummaryOperand Operate
method.
As you can see in the code snippet below the operate method has the following three parameters:
- columnData - gives you an array that contains the values only for the current column
- allGridData - gives you the whole grid data source
- fieldName - current column field
class WebGridDiscontinuedSummary {
operate(data, allData, fieldName) {
const discontinuedData = allData.filter((rec) => rec['Discontinued']).map(r => r[fieldName]);
result.push({
key: 'totalDiscontinued',
label: 'Total Discontinued Items',
summaryResult: discontinuedData.length ? discontinuedData.reduce((a, b) => +a + +b) : 0
});
return result;
}
}
Summary Template
Summary
targets the column summary providing as a context the column summary results.
<IgbColumn HasSummary="true" SummaryTemplateScript="SummaryTemplate">
</IgbColumn>
igRegisterScript("SummaryTemplate", (ctx) => {
var html = window.igTemplating.html;
return html`<div>
<span> ${ctx.implicit[0].label} - ${ctx.implicit[0].summaryResult} </span>
</div>`
}, false);
When a default summary is defined, the height of the summary area is calculated by design depending on the column with the largest number of summaries and the --ig-size
of the grid. Use the SummaryRowHeight
input property to override the default value. As an argument it expects a number value, and setting a falsy value will trigger the default sizing behavior of the grid footer.
Disabled Summaries
The DisabledSummaries
property provides precise per-column control over the Blazor Hierarchical Grid summary feature. This property enables users to customize the summaries displayed for each column in the HierarchicalGrid, ensuring that only the most relevant and meaningful data is shown. For example, you can exclude specific summary types, such as ['count', 'min', 'max']
by specifying their summary keys in an array.
This property can also be modified dynamically at runtime through code, providing flexibility to adapt the HierarchicalGrid's summaries to changing application states or user actions.
The following examples illustrate how to use the DisabledSummaries
property to manage summaries for different columns and exclude specific default and custom summary types in the Blazor Hierarchical Grid:
<!-- Disable default summaries -->
<IgbColumn
Field="UnitPrice"
Header="Unit Price"
DataType="GridColumnDataType.Number"
HasSummary="true"
DisabledSummaries="['count', 'sum', 'average']" />
<!-- Disable custom summaries -->
<IgbColumn
Field="UnitsInStock"
Header="Units In Stock"
DataType="GridColumnDataType.Number"
HasSummary="true"
Summaries="discontinuedSummary"
DisabledSummaries="['discontinued', 'totalDiscontinued']" />
For UnitPrice
, default summaries like count
, sum
, and average
are disabled, leaving others like min
and max
active.
For UnitsInStock
, custom summaries such as discontinued
and totalDiscontinued
are excluded using the DisabledSummaries
property.
At runtime, summaries can also be dynamically disabled using the DisabledSummaries
property. For example, you can set or update the property on specific columns programmatically to adapt the displayed summaries based on user actions or application state changes.
Keyboard Navigation
The summary rows can be navigated with the following keyboard interactions:
- UP - navigates one cell up.
- DOWN - navigates one cell down.
- LEFT - navigates one cell left.
- RIGHT - navigates one cell right.
- CTRL + LEFT or HOME - navigates to the leftmost cell.
- CTRL + RIGHT or END - navigates to the rightmost cell.
Styling
In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties. In case you would like to change some of the colors, you need to set a class for the grid first:
<IgbHierarchicalGrid id="hierarchicalGrid"></IgbHierarchicalGrid>
Then set the related CSS properties for that class:
#hierarchicalGrid {
--ig-grid-summary-background-color:#e0f3ff;
--ig-grid-summary-focus-background-color: rgba( #94d1f7, .3 );
--ig-grid-summary-label-color: rgb(228, 27, 117);
--ig-grid-summary-result-color: black;
}
Demo
API References
SummaryOperand
NumberSummaryOperand
DateSummaryOperand
IgbColumnGroup
IgbColumn
Additional Resources
Our community is active and always welcoming to new ideas.