React Hierarchical Grid Summaries
The Ignite UI for React Summaries feature in React Hierarchical Grid functions on a per-column level as group footer. React IgrHierarchicalGrid 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 IgrHierarchicalGrid
.
React 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
IgrHierarchicalGrid
summaries can also be enabled on a per-column level in Ignite UI for React, which means that you can activate it only for columns that you need. IgrHierarchicalGrid
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.
IgrHierarchicalGrid
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 IgrHierarchicalGrid
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
.
<IgrHierarchicalGrid autoGenerate="false" data={this.singersData} ref={this.hierarchicalGridRef} id="hierarchicalGrid" primaryKey="ID">
<IgrColumn field="Artist" header="Artist" hasSummary="true"></IgrColumn>
<IgrColumn field="Photo" header="Photo" dataType="Image"></IgrColumn>
<IgrColumn field="Debut" header="Debut" hasSummary="true"></IgrColumn>
<IgrColumn field="GrammyNominations" header="Grammy Nominations" dataType="Number" hasSummary="true"></IgrColumn>
<IgrColumn field="GrammyAwards" header="Grammy Awards" dataType="Number" hasSummary="true"></IgrColumn>
<IgrRowIsland childDataKey="Albums" autoGenerate="false">
<IgrColumn field="Album" header="Album" dataType="String"></IgrColumn>
<IgrColumn field="LaunchDate" header="Launch Date" dataType="Date"></IgrColumn>
<IgrColumn field="BillboardReview" header="Billboard Review" dataType="Number" hasSummary="true"></IgrColumn>
<IgrColumn field="USBillboard200" header="US Billboard 200" dataType="Number" hasSummary="true" ></IgrColumn>
</IgrRowIsland>
</IgrHierarchicalGrid>
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 IgrHierarchicalGrid
.
function enableSummary() {
hierarchicalGridRef.current.enableSummaries([
{fieldName: 'GrammyNominations'},
{fieldName: 'GrammyAwards'}
]);
}
function disableSummary() {
hierarchicalGridRef.current.disableSummaries(['GrammyNominations']);
}
<IgrHierarchicalGrid autoGenerate="false" data={this.singersData} ref={this.hierarchicalGridRef} id="hierarchicalGrid" primaryKey="ID">
<IgrColumn field="Artist" header="Artist" hasSummary="true"></IgrColumn>
<IgrColumn field="Photo" header="Photo" dataType="Image"></IgrColumn>
<IgrColumn field="Debut" header="Debut" hasSummary="true"></IgrColumn>
<IgrColumn field="GrammyNominations" header="Grammy Nominations" dataType="Number" hasSummary="true"></IgrColumn>
<IgrColumn field="GrammyAwards" header="Grammy Awards" dataType="Number" hasSummary="true"></IgrColumn>
</IgrHierarchicalGrid>
<button onClick={enableSummary}>Enable Summary</button>
<button onClick={disableSummary}>Disable Summary </button>
Summary Template
Summary
targets the column summary providing as a context the column summary results.
function summaryTemplate(ctx: IgrSummaryTemplateContext) {
return (
<>
<span>My custom summary template</span>
<span>{ctx.dataContext.implicit[0].label} - {ctx.dataContext.implicit[0].summaryResult}</span>
</>
);
}
<IgrColumn hasSummary="true" summaryTemplate={summaryTemplate}></IgrColumn>
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 React Hierarchical Grid summary feature. This property enables users to customize the summaries displayed for each column in the IgrHierarchicalGrid, 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 IgrHierarchicalGrid'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 React Hierarchical Grid:
<!-- Disable default summaries -->
<IgrColumn
field="UnitPrice"
header="Unit Price"
dataType="number"
hasSummary={true}
disabledSummaries="['count', 'sum', 'average']"
/>
<!-- Disable custom summaries -->
<IgrColumn
field="UnitsInStock"
header="Units In Stock"
dataType="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.
Formatting summaries
By default, summary results, produced by the built-in summary operands, are localized and formatted according to the grid locale
and column pipeArgs
. When using custom operands, the locale
and pipeArgs
are not applied. If you want to change the default appearance of the summary results, you may format them using the summaryFormatter
property.
public summaryFormatter(
summary: IgrSummaryResult,
summaryOperand: IgrSummaryOperand
): string {
const result = summary.summaryResult;
if (summary.key !== "count" && result !== null && result !== undefined) {
const format = new Intl.DateTimeFormat("en", { year: "numeric" });
return format.format(new Date(result));
}
return result;
}
<IgrColumn hasSummary="true" summaryFormatter={this.summaryFormatter}></IgrColumn>
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:
<IgrHierarchicalGrid id="hierarchicalGrid">
</IgrHierarchicalGrid>
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
Additional Resources
Our community is active and always welcoming to new ideas.