Angular Hierarchical Grid Summaries
The Angular UI grid in Ignite UI for Angular has a summaries feature that functions on a per-column level as group footer. Angular grid 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 angular template in the Hierarchical Grid.
Angular Hierarchical Grid Summaries Overview Example
import { Component, ViewChild } from '@angular/core' ;
import { IgxHierarchicalGridComponent, IgxNumberSummaryOperand, IgxSummaryResult, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class MySummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push(
{
key : 'min' ,
label : 'Min' ,
summaryResult : IgxNumberSummaryOperand.min(data)
},
{
key : 'max' ,
label : 'Max' ,
summaryResult : IgxNumberSummaryOperand.max(data)
},
{
key : 'avg' ,
label : 'Avg' ,
summaryResult : IgxNumberSummaryOperand.average(data)
});
return result;
}
}
class MyChildSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push(
{
key : 'count' ,
label : 'Count' ,
summaryResult : IgxNumberSummaryOperand.count(data)
});
return result;
}
}
@Component ({
selector : 'app-hierarchical-grid-summary' ,
styleUrls : ['./hierarchical-grid-summary.component.scss' ],
templateUrl : 'hierarchical-grid-summary.component.html' ,
imports : [IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent]
})
export class HGridSummarySampleComponent {
@ViewChild ('hierarchicalGrid' , { static : true })
private hierarchicalGrid: IgxHierarchicalGridComponent;
public localdata;
public mySummary = MySummary;
public myChildSummary = MyChildSummary;
constructor ( ) {
this .localdata = SINGERS;
}
public formatter = (a ) => a;
}
ts コピー <div class ="hgrid-sample" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="localdata" [autoGenerate ]="false"
[height ]="'600px'" [width ]="'100%'" [rowHeight ]="'65px'" #hierarchicalGrid >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [hasSummary ]='true' [formatter ]="formatter" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [hasSummary ]='true' [summaries ]="mySummary" dataType ="number" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [autoGenerate ]="false" >
<igx-column field ="Album" > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [dataType ]="'date'" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" [autoGenerate ]="false" >
<igx-column field ="Number" header ="No." > </igx-column >
<igx-column field ="Title" [hasSummary ]='true' [summaries ]="myChildSummary" > </igx-column >
<igx-column field ="Released" dataType ="date" > </igx-column >
<igx-column field ="Genre" > </igx-column >
</igx-row-island >
</igx-row-island >
<igx-row-island [height ]="null" [key ]="'Tours'" [autoGenerate ]="false" >
<igx-column field ="Tour" > </igx-column >
<igx-column field ="StartedOn" header ="Started on" > </igx-column >
<igx-column field ="Location" > </igx-column >
<igx-column field ="Headliner" > </igx-column >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー .photo {
vertical-align : middle;
max-height : 62px ;
}
.cell__inner_2 {
margin : 1px
}
.hgrid-sample{
padding: 16px ;
}
scss コピー
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
Hierarchical Grid summaries can also be enabled on a per-column level in Ignite UI for Angular, which means that you can activate it only for columns that you need. Hierarchical Grid 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
data types
, the following function is available:
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:
All available column data types could be found in the official Column types topic .
Hierarchical Grid 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 igx-hierarchical-grid
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
.
<igx-hierarchical-grid class ="hgrid" [data ]="localdata" [autoGenerate ]="false" >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [hasSummary ]='true' > </igx-column >
<igx-column field ="Grammy Nominations" [hasSummary ]='true' [dataType ]="'number'" [summaries ]="mySummary" > </igx-column >
<igx-column field ="Grammy Awards" [hasSummary ]='true' [dataType ]="'number'" > </igx-column >
</igx-hierarchical-grid >
html
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 igx-hierarchical-grid .
<igx-hierarchical-grid #hierarchicalGrid [data ]="data" [autoGenerate ]="false" height ="800px" width ="800px" (columnInit )="initColumn($event)" >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [hasSummary ]='true' > </igx-column >
<igx-column field ="Grammy Nominations" [hasSummary ]='true' [dataType ]="'number'" [summaries ]="mySummary" > </igx-column >
<igx-column field ="Grammy Awards" [hasSummary ]='true' [dataType ]="'number'" > </igx-column >
</igx-hierarchical-grid >
<button (click )="enableSummary()" > Enable Summary</button >
<button (click )="disableSummary()" > Disable Summary </button >
html
public enableSummary ( ) {
this .hierarchicalGrid.enableSummaries([
{fieldName : 'Grammy Nominations' , customSummary : this .mySummary},
{fieldName : 'Artist' }
]);
}
public disableSummary ( ) {
this .hierarchicalGrid.disableSummaries('Photo' );
}
typescript
Custom Hierarchical Grid Summaries
If these functions do not fulfill your requirements you can provide a custom summary for the specific columns. In order to achieve this you have to override one of the base classes IgxSummaryOperand
, IgxNumberSummaryOperand
or IgxDateSummaryOperand
according to the column data type and your needs. This way you can redefine the existing function or you can add new functions. IgxSummaryOperand
class provides the default implementation only for the count
method. IgxNumberSummaryOperand
extends IgxSummaryOperand
and provides implementation for the min
, max
, sum
and average
. IgxDateSummaryOperand
extends IgxSummaryOperand
and additionally gives you earliest
and latest
.
import { IgxRowIslandComponent, IgxHierarchicalGridComponent, IgxNumberSummaryOperand, IgxSummaryResult } from 'igniteui-angular' ;
class MySummary extends IgxNumberSummaryOperand {
constructor ( ) {
super ();
}
public operate(data?: any []): IgxSummaryResult[] {
const result = super .operate(data);
result.push({
key : 'test' ,
label : 'More than 5' ,
summaryResult : data.filter((rec ) => rec > 5 ).length
});
return result;
}
}
typescript
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 IgxSummaryResult
.
interface IgxSummaryResult {
key : string ;
label: string ;
summaryResult: any ;
}
typescript
and take optional parameters for calculating the summaries.
See Custom summaries, which access all data section below.
In order to calculate the summary row height properly, the Hierarchical Grid needs the operate
method to always return an array of IgxSummaryResult
with the proper length even when the data is empty.
And now let's add our custom summary to the column GramyNominations
. We will achieve that by setting the summaries
property to the class we create below.
<igx-hierarchical-grid class ="hgrid" [data ]="localdata" [autoGenerate ]="false" >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [hasSummary ]='true' > </igx-column >
<igx-column field ="Grammy Nominations" [hasSummary ]='true' [dataType ]="'number'" [summaries ]="mySummary" > </igx-column >
<igx-column field ="Grammy Awards" [hasSummary ]='true' [dataType ]="'number'" > </igx-column >
</igx-hierarchical-grid >
html
...
export class HGridSummarySampleComponent implements OnInit {
mySummary = MySummary;
....
}
typescript
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 IgxSummaryOperand 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 MySummary extends IgxNumberSummaryOperand {
constructor ( ) {
super ();
}
operate(columnData: any [], allGridData = [], fieldName?): IgxSummaryResult[] {
const result = super .operate(allData.map(r => r[fieldName]));
result.push({ key : 'test' , label : 'Total Discontinued' , summaryResult : allData.filter((rec ) => rec.Discontinued).length });
return result;
}
}
typescript
import { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxHierarchicalGridComponent, IgxNumberSummaryOperand, IgxSummaryOperand, IgxSummaryResult, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class CustomNumberSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = new IgxNumberSummaryOperand().operate(data);
result.pop();
result.pop();
return result;
}
}
class GrammySummary {
public operate(data?: any [], allData = [], fieldName = '' ): IgxSummaryResult[] {
const result = [];
result.push({
key : 'nominatedSingers' ,
label : 'Nominated Singers' ,
summaryResult : allData.filter((rec ) => rec['GrammyNominations' ] > 0 ).length
});
result.push({
key : 'singersWithAwards' ,
label : 'Singers with Awards' ,
summaryResult : allData.filter((rec ) => rec['GrammyAwards' ] > 0 ).length
});
result.push({
key : 'nominations' ,
label : 'Total Nominations' ,
summaryResult : IgxNumberSummaryOperand.sum(allData.map(r => r['GrammyNominations' ]))
});
result.push({
key : 'awards' ,
label : 'Total Awards' ,
summaryResult : IgxNumberSummaryOperand.sum(allData.map(r => r['GrammyAwards' ]))
});
return result;
}
}
@Component ({
selector : 'app-hierarchical-grid-all-data-summary' ,
styleUrls : ['./hierarchical-grid-allData-summary.component.scss' ],
templateUrl : 'hierarchical-grid-allData-summary.component.html' ,
imports : [IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent]
})
export class HGridAllDataSummaryComponent implements OnInit {
@ViewChild ('hierarchicalGrid' , { static : true })
private hierarchicalGrid: IgxHierarchicalGridComponent;
public localdata;
public grammySummary = GrammySummary;
public numberSummary = CustomNumberSummary;
constructor ( ) {}
public ngOnInit(): void {
this .localdata = SINGERS;
}
}
ts コピー <div class ="hgrid-sample" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="localdata"
[height ]="'600px'" [width ]="'100%'" [rowHeight ]="'65px'" #hierarchicalGrid >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" [hasSummary ]='true' [summaries ]="grammySummary" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [hasSummary ]='true' [dataType ]="'number'" [summaries ]="numberSummary" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [hasSummary ]='true' [dataType ]="'number'" [summaries ]="numberSummary" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" >
<igx-column field ="Album" [hasSummary ]='true' > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [hasSummary ]='true' [dataType ]="'date'" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [hasSummary ]='true' > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [hasSummary ]='true' > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" >
<igx-column field ="Number" header ="No." [hasSummary ]='true' > </igx-column >
<igx-column field ="Title" [hasSummary ]='true' > </igx-column >
<igx-column field ="Released" dataType ="date" [hasSummary ]='true' > </igx-column >
<igx-column field ="Genre" [hasSummary ]='true' > </igx-column >
</igx-row-island >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー .hgrid-sample {
padding : 16px ;
}
scss コピー
Summary Template
igxSummary
targets the column summary providing as a context the column summary results.
<igx-column ... [hasSummary ]="true" >
<ng-template igxSummary let-summaryResults >
<span > My custom summary template</span >
<span > {{ summaryResults[0].label }} - {{ summaryResults[0].summaryResult }}</span >
</ng-template >
</igx-column >
html
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 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 false value will trigger the default sizing behavior of the grid footer.
Column summary template could be defined through API by setting the column summaryTemplate property to the required TemplateRef.
import { Component, HostBinding, OnInit } from '@angular/core' ;
import { IgxNumberSummaryOperand, IgxSummaryResult, IgxInputGroupComponent, IgxLabelDirective, IgxInputDirective, IgxSwitchComponent, IgxButtonGroupComponent, IgxHierarchicalGridComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxSummaryTemplateDirective, IgxRowIslandComponent } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { FormsModule } from '@angular/forms' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class CustomNumberSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = new IgxNumberSummaryOperand().operate(data);
result.pop();
result.pop();
return result;
}
}
class GrammySummary {
public operate(data?: any [], allData = [], fieldName = '' ): IgxSummaryResult[] {
const result = [];
result.push({
key : 'nominatedSingers' ,
label : 'Nominated Singers' ,
summaryResult : allData.filter((rec ) => rec['GrammyNominations' ] > 0 ).length
});
result.push({
key : 'singersWithAwards' ,
label : 'Singers with Awards' ,
summaryResult : allData.filter((rec ) => rec['GrammyAwards' ] > 0 ).length
});
result.push({
key : 'nominations' ,
label : 'Total Nominations' ,
summaryResult : IgxNumberSummaryOperand.sum(allData.map(r => r['GrammyNominations' ]))
});
result.push({
key : 'awards' ,
label : 'Total Awards' ,
summaryResult : IgxNumberSummaryOperand.sum(allData.map(r => r['GrammyAwards' ]))
});
return result;
}
}
@Component ({
selector : 'app-hierarchical-grid-all-data-summary' ,
styleUrls : ['./hgrid-summary-template.component.scss' ],
templateUrl : 'hgrid-summary-template.component.html' ,
imports : [IgxInputGroupComponent, IgxLabelDirective, FormsModule, IgxInputDirective, IgxSwitchComponent, IgxButtonGroupComponent, IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxSummaryTemplateDirective, IgxRowIslandComponent]
})
export class HGridSummaryTemplateComponent implements OnInit {
public localdata;
public grammySummary = GrammySummary;
public numberSummary = CustomNumberSummary;
public summaryHeight = 120 ;
public size = 'medium' ;
public sizes;
public hasSummary = true ;
constructor ( ) { }
public ngOnInit(): void {
this .localdata = SINGERS;
this .sizes = [
{ label : 'small' , selected : this .size === 'small' , togglable : true },
{ label : 'medium' , selected : this .size === 'medium' , togglable : true },
{ label : 'large' , selected : this .size === 'large' , togglable : true }
];
}
@HostBinding ('style.--ig-size' )
protected get sizeStyle () {
return `var(--ig-size-${this .size} )` ;
}
public selectSize(event): void {
this .size = this .sizes[event.index].label;
}
}
ts コピー <div class ="sample__wrapper" >
<div class ="controls-wrapper" >
<igx-input-group >
<label igxLabel for ="height" > Summary Row Height</label >
<input igxInput name ="height" type ="number" [(ngModel )]="summaryHeight" >
</igx-input-group >
<igx-switch [(ngModel )]="hasSummary" > Toggle Summaries</igx-switch >
<igx-buttongroup [values ]="sizes" (selected )="selectSize($event)" >
</igx-buttongroup >
</div >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" [data ]="localdata"
[summaryRowHeight ]="summaryHeight" [height ]="'550px'" [width ]="'100%'" [rowHeight ]="'65px'" #hierarchicalGrid >
<igx-column field ="Artist" [hasSummary ]='hasSummary' > </igx-column >
<igx-column field ="Photo" [hasSummary ]='hasSummary' [summaries ]="grammySummary" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [hasSummary ]='hasSummary'
[dataType ]="'number'" [summaries ]="numberSummary" >
<ng-template igxSummary let-summaryResults >
<div class ="summary-temp" >
<span > <strong > {{ summaryResults[0].label }}</strong > <span > {{ summaryResults[0].summaryResult }}</span > </span >
<span > <strong > {{ summaryResults[1].label }}</strong > <span > {{ summaryResults[1].summaryResult }}</span > </span >
<span > <strong > {{ summaryResults[2].label }}</strong > <span > {{ summaryResults[2].summaryResult }}</span > </span >
</div >
</ng-template >
</igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [hasSummary ]='hasSummary' [dataType ]="'number'"
[summaries ]="numberSummary" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [summaryRowHeight ]="summaryHeight" >
<igx-column field ="Album" [hasSummary ]='hasSummary' > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [hasSummary ]='hasSummary' [dataType ]="'date'" >
<ng-template igxSummary let-summaryResults >
<div class ="summary-temp" >
<span > <strong > {{ summaryResults[0].label }}</strong > <span > {{ summaryResults[0].summaryResult }}</span > </span >
<span > <strong > {{ summaryResults[1].label }}</strong > <span > {{ summaryResults[1].summaryResult }}</span > </span >
</div >
</ng-template >
</igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [hasSummary ]='hasSummary' > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [hasSummary ]='hasSummary' > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" >
<igx-column field ="Number" header ="No." [hasSummary ]='hasSummary' > </igx-column >
<igx-column field ="Title" [hasSummary ]='hasSummary' > </igx-column >
<igx-column field ="Released" dataType ="date" [hasSummary ]='hasSummary' > </igx-column >
<igx-column field ="Genre" [hasSummary ]='hasSummary' > </igx-column >
</igx-row-island >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー .sample__wrapper {
display : flex;
flex-direction : column;
gap: 16px ;
padding : 16px ;
height : 100% ;
overflow-y : auto;
}
igx-buttongroup {
max-width : 450px ;
flex : 1 ;
}
.summary-temp {
display : flex;
flex-direction : column;
margin : 0 1px ;
font-size : 14px ;
line-height : 24px ;
height : 100% ;
overflow-y : auto;
overflow-x : hidden;
span {
display : flex;
flex-wrap : wrap;
align-items : center;
gap: 4px ;
justify-content : space-between;
color : hsla(var(--igx-gray-900 ));
span {
user-select: all;
max-width : 300px ;
padding-right : 8px ;
}
strong {
font-size : 12px ;
text-transform : uppercase;
min-width : 70px ;
justify-self: flex-start;
text-align : left;
color : var(--ig-secondary-600 );
user-select: none;
}
}
> * {
padding : 8px 0 ;
line-height : 18px ;
border-bottom : 1px dashed hsla(var(--igx-gray-400 ));
&:last-child {
border-bottom : none;
}
}
}
::-webkit-scrollbar {
width: 5px !important ;
height : 5px !important ;
}
.controls-wrapper {
display : flex;
align-items : center;
flex-direction : row;
gap: 16px ;
}
scss コピー
Disable Summaries
The disabledSummaries
property provides precise per-column control over the Ignite UI for Angular grid summary feature. This property enables users to customize the summaries displayed for each column in the grid, 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 grid'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 Ignite UI for Angular grid:
<igx-column
field ="Photo"
[hasSummary ]="true"
[summaries ]="grammySummary"
[disabledSummaries ]="['singersWithAwards', 'awards']"
>
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column
field ="GrammyNominations"
header ="Grammy Nominations"
dataType ="number"
[hasSummary ]="true"
[disabledSummaries ]="['count', 'sum', 'average']"
> </igx-column >
html
For Photo
, custom summaries such as singersWithAwards
and awards
are excluded using the disabledSummaries
property.
For GrammyNominations
default summaries like count
, sum
, and average
are disabled, leaving others like min
and max
active.
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.
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 dateSummaryFormat(summary: IgxSummaryResult, summaryOperand : IgxSummaryOperand): string {
const result = summary.summaryResult;
if (summaryOperand instanceof IgxDateSummaryOperand && summary.key !== 'count'
&& result !== null && result !== undefined ) {
const pipe = new DatePipe('en-US' );
return pipe.transform(result,'MMM YYYY' );
}
return result;
}
typescript
<igx-column ... [summaryFormatter ]="dateSummaryFormat" > </igx-column >
html
import { DatePipe } from '@angular/common' ;
import { Component, ViewChild } from '@angular/core' ;
import { IgxDateSummaryOperand, IgxHierarchicalGridComponent, IgxSummaryOperand, IgxSummaryResult, IgxColumnComponent, IgxRowIslandComponent } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
@Component ({
selector : 'app-hierarchical-grid-summary-formatter' ,
styleUrls : ['./hierarchical-grid-summary-formatter.component.scss' ],
templateUrl : 'hierarchical-grid-summary-formatter.component.html' ,
imports : [IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxRowIslandComponent]
})
export class HGridSummaryFormatterComponent {
@ViewChild ('hierarchicalGrid' , { static : true })
public hierarchicalGrid: IgxHierarchicalGridComponent;
public localdata;
constructor ( ) {
this .localdata = SINGERS;
}
public decadeFormatter = (value: number ) => Math .floor(value / 10 ) * 10 + 's' ;
public dateSummaryFormat(summary: IgxSummaryResult, summaryOperand : IgxSummaryOperand): string {
const result = summary.summaryResult;
if (summaryOperand instanceof IgxDateSummaryOperand && summary.key !== 'count'
&& result !== null && result !== undefined ) {
const pipe = new DatePipe('en-US' );
return pipe.transform(result, 'MMM YYYY' );
}
return result;
}
}
ts コピー <div class ="wrapper" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="localdata" [autoGenerate ]="false"
[allowFiltering ]='true' filterMode ="excelStyleFilter" [expandChildren ]="true"
height ="600px" [width ]="'100%'" #hierarchicalGrid >
<igx-column field ="Artist" [sortable ]="true" [disableHiding ]="true" > </igx-column >
<igx-column field ="Debut" header ="Debut Decade" [sortable ]="true" [disableHiding ]="true" [formatter ]="decadeFormatter" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" dataType ="number" [sortable ]="true" [disableHiding ]="true" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" dataType ="number" [sortable ]="true" [disableHiding ]="true" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [autoGenerate ]="false" [allowFiltering ]='true' filterMode ="excelStyleFilter" >
<igx-column field ="Album" [sortable ]="true" [disableHiding ]="true" > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [sortable ]="true" [disableHiding ]="true" [dataType ]="'date'" [hasSummary ]="true"
[summaryFormatter ]="dateSummaryFormat" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [sortable ]="true" [disableHiding ]="true" dataType ="number" > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [sortable ]="true" [disableHiding ]="true" dataType ="number" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" [autoGenerate ]="false" >
<igx-column field ="Number" header ="No." > </igx-column >
<igx-column field ="Title" > </igx-column >
<igx-column field ="Released" dataType ="date" > </igx-column >
<igx-column field ="Genre" > </igx-column >
</igx-row-island >
</igx-row-island >
<igx-row-island [height ]="null" [key ]="'Tours'" [autoGenerate ]="false" >
<igx-column field ="Tour" > </igx-column >
<igx-column field ="StartedOn" header ="Started on" > </igx-column >
<igx-column field ="Location" > </igx-column >
<igx-column field ="Headliner" > </igx-column >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー .wrapper {
margin : 16px ;
}
scss コピー
Exporting Summaries
There is an exportSummaries
option in IgxExcelExporterOptions
that specifies whether the exported data should include the grid's summaries. Default exportSummaries
value is false .
The IgxExcelExporterService
will export the default summaries for all column types as their equivalent excel functions so they will continue working properly when the sheet is modified. Try it for yourself in the example below:
import { Component, OnInit, ViewChild, inject } from '@angular/core' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxExcelExporterOptions, IgxExcelExporterService, IgxHierarchicalGridComponent, IgxNumberSummaryOperand, IgxSummaryResult, IgxButtonDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent } from 'igniteui-angular' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class MySummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push(
{
key : 'min' ,
label : 'Min' ,
summaryResult : IgxNumberSummaryOperand.min(data)
},
{
key : 'max' ,
label : 'Max' ,
summaryResult : IgxNumberSummaryOperand.max(data)
},
{
key : 'avg' ,
label : 'Avg' ,
summaryResult : IgxNumberSummaryOperand.average(data)
});
return result;
}
}
class MyChildSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push(
{
key : 'count' ,
label : 'Count' ,
summaryResult : IgxNumberSummaryOperand.count(data)
});
return result;
}
}
@Component ({
selector : 'app-hierarchical-grid-summary-export' ,
styleUrls : ['./hgrid-summary-export.component.scss' ],
templateUrl : 'hgrid-summary-export.component.html' ,
imports : [IgxButtonDirective, IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent]
})
export class HGridSummaryExportComponent {
private excelExportService = inject(IgxExcelExporterService);
@ViewChild ('hGrid' , { static : true })
private hGrid: IgxHierarchicalGridComponent;
public data;
public mySummary = MySummary;
public myChildSummary = MyChildSummary;
constructor ( ) {
this .data = SINGERS;
}
public exportButtonHandler ( ) {
this .excelExportService.export(this .hGrid, new IgxExcelExporterOptions('ExportedFile' ));
}
}
ts コピー <div class ="hgrid-sample" >
<div class ="button-container" >
<button igxButton ="contained" (click )="exportButtonHandler()" > Export To Excel</button >
Press the button to export the Grid as a .xlsx file.
</div >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="data" [autoGenerate ]="false"
[height ]="'650px'" [width ]="'100%'" [rowHeight ]="'65px'" #hGrid >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [hasSummary ]='true' > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [hasSummary ]='true' [summaries ]="mySummary" dataType ="number" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [autoGenerate ]="false" >
<igx-column field ="Album" > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [dataType ]="'date'" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" [autoGenerate ]="false" >
<igx-column field ="Number" header ="No." > </igx-column >
<igx-column field ="Title" [hasSummary ]='true' [summaries ]="myChildSummary" > </igx-column >
<igx-column field ="Released" dataType ="date" > </igx-column >
<igx-column field ="Genre" > </igx-column >
</igx-row-island >
</igx-row-island >
<igx-row-island [height ]="null" [key ]="'Tours'" [autoGenerate ]="false" >
<igx-column field ="Tour" > </igx-column >
<igx-column field ="StartedOn" header ="Started on" > </igx-column >
<igx-column field ="Location" > </igx-column >
<igx-column field ="Headliner" > </igx-column >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー .sample__wrapper {
display : flex;
flex-direction : column;
gap: 16px ;
padding : 16px ;
height : 100% ;
overflow-y : auto;
}
igx-buttongroup {
max-width : 450px ;
flex : 1 ;
}
.summary-temp {
display : flex;
flex-direction : column;
margin : 0 1px ;
font-size : 14px ;
line-height : 24px ;
height : 100% ;
overflow-y : auto;
overflow-x : hidden;
span {
display : flex;
flex-wrap : wrap;
align-items : center;
gap: 4px ;
justify-content : space-between;
color : var(--ig-gray-900 );
span {
user-select: all;
max-width : 300px ;
padding-right : 8px ;
}
strong {
font-size : 12px ;
text-transform : uppercase;
min-width : 70px ;
justify-self: flex-start;
text-align : left;
color : var(--ig-secondary-600 );
user-select: none;
}
}
> * {
padding : 8px 0 ;
line-height : 18px ;
border-bottom : 1px dashed var(--ig-gray-400 );
&:last-child {
border-bottom : none;
}
}
}
::-webkit-scrollbar {
width: 5px !important ;
height : 5px !important ;
}
.controls-wrapper {
display : flex;
align-items : center;
flex-direction : row;
gap: 16px ;
}
.button-container {
margin : 25px auto;
}
scss コピー
The exported file includes a hidden column that holds the level of each DataRecord
in the sheet. This level is used in the summaries to filter out the cells that need to be included in the summary function.
In the table below, you can find the corresponding Excel formula for each of the default summaries.
Data Type
Function
Excel Function
string
, boolean
count
="Count: "&COUNTIF(start:end, recordLevel)
number
, currency
, percent
count
="Count: "&COUNTIF(start:end, recordLevel)
min
="Min: "&MIN(IF(start:end=recordLevel, rangeStart:rangeEnd))
max
="Max: "&MAX(IF(start:end=recordLevel, rangeStart:rangeEnd))
average
="Avg: "&AVERAGEIF(start:end, recordLevel, rangeStart:rangeEnd)
sum
="Sum: "&SUMIF(start:end, recordLevel, rangeStart:rangeEnd)
date
count
="Count: "&COUNTIF(start:end, recordLevel)
earliest
="Earliest: "& TEXT(MIN(IF(start:end=recordLevel, rangeStart:rangeEnd)), format)
latest
="Latest: "&TEXT(MAX(IF(start:end=recordLevel, rangeStart:rangeEnd)), format)
Known Limitations
Limitation
Description
Exporting custom summaries
Custom summaries will be exported as strings instead of Excel functions.
Exporting templated summaries
Templated summaries are not supported and will be exported as the default ones.
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
To get started with styling the sorting behavior, we need to import the index
file, where all the theme functions and component mixins live:
@use "igniteui-angular/theming" as *;
scss
Following the simplest approach, we create a new theme that extends the grid-summary-theme
and accepts the $background-color
, $focus-background-color
, $label-color
, $result-color
, $pinned-border-width
, $pinned-border-style
and $pinned-border-color
parameters.
$custom-theme : grid-summary-theme(
$background-color : #e0f3ff ,
$focus-background-color : rgba(#94d1f7 , .3 ),
$label-color : #e41c77 ,
$result-color : black,
$pinned-border-width : 2px ,
$pinned-border-style : dotted,
$pinned-border-color : #e41c77
);
scss
Instead of hardcoding the color values like we just did, we can achieve greater flexibility in terms of colors by using the palette
and color
functions. Please refer to Palettes
topic for detailed guidance on how to use them.
The last step is to include the component custom theme:
@include css-vars($custom-theme );
scss
If the component is using an Emulated
ViewEncapsulation, it is necessary to penetrate
this encapsulation using ::ng-deep
:
:host {
::ng-deep {
@include css-vars($custom-theme );
}
}
scss
Demo
import { Component } from '@angular/core' ;
import { IgxNumberSummaryOperand, IgxSummaryResult, IgxHierarchicalGridComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent } from 'igniteui-angular' ;
import { SINGERS } from '../../data/singersData' ;
import { IgxPreventDocumentScrollDirective } from '../../directives/prevent-scroll.directive' ;
class MySummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push(
{
key : 'min' ,
label : 'Min' ,
summaryResult : IgxNumberSummaryOperand.min(data)
},
{
key : 'max' ,
label : 'Max' ,
summaryResult : IgxNumberSummaryOperand.max(data)
},
{
key : 'avg' ,
label : 'Avg' ,
summaryResult : IgxNumberSummaryOperand.average(data)
});
return result;
}
}
class MyChildSummary {
public operate(data?: any []): IgxSummaryResult[] {
const result = [];
result.push(
{
key : 'count' ,
label : 'Count' ,
summaryResult : IgxNumberSummaryOperand.count(data)
});
return result;
}
}
@Component ({
selector : 'app-hierarchical-grid-summary-styling' ,
styleUrls : ['./hierarchical-grid-summary-styling.component.scss' ],
templateUrl : 'hierarchical-grid-summary-styling.component.html' ,
imports : [IgxHierarchicalGridComponent, IgxPreventDocumentScrollDirective, IgxColumnComponent, IgxCellTemplateDirective, IgxRowIslandComponent]
})
export class HGridSummaryStylingComponent {
public localdata;
public mySummary = MySummary;
public myChildSummary = MyChildSummary;
constructor ( ) {
this .localdata = SINGERS;
}
public formatter = (a ) => a;
}
ts コピー <div class ="hgrid-sample" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" class ="hgrid" [data ]="localdata" [autoGenerate ]="false"
[height ]="'650px'" [width ]="'100%'" [rowHeight ]="'65px'" #hierarchicalGrid >
<igx-column field ="Artist" [hasSummary ]='true' > </igx-column >
<igx-column field ="Photo" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner_2" >
<img [src ]="cell.value" class ="photo" />
</div >
</ng-template >
</igx-column >
<igx-column field ="Debut" [hasSummary ]='true' [formatter ]="formatter" > </igx-column >
<igx-column field ="GrammyNominations" header ="Grammy Nominations" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-column field ="GrammyAwards" header ="Grammy Awards" [hasSummary ]='true' [summaries ]="mySummary" dataType ="number" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Albums'" [autoGenerate ]="false" >
<igx-column field ="Album" > </igx-column >
<igx-column field ="LaunchDate" header ="Launch Date" [dataType ]="'date'" > </igx-column >
<igx-column field ="BillboardReview" header ="Billboard Review" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-column field ="USBillboard200" header ="US Billboard 200" [hasSummary ]='true' dataType ="number" [summaries ]="mySummary" > </igx-column >
<igx-row-island [height ]="null" [key ]="'Songs'" [autoGenerate ]="false" >
<igx-column field ="Number" header ="No." > </igx-column >
<igx-column field ="Title" [hasSummary ]='true' [summaries ]="myChildSummary" > </igx-column >
<igx-column field ="Released" dataType ="date" > </igx-column >
<igx-column field ="Genre" > </igx-column >
</igx-row-island >
</igx-row-island >
<igx-row-island [height ]="null" [key ]="'Tours'" [autoGenerate ]="false" >
<igx-column field ="Tour" > </igx-column >
<igx-column field ="StartedOn" header ="Started on" > </igx-column >
<igx-column field ="Location" > </igx-column >
<igx-column field ="Headliner" > </igx-column >
</igx-row-island >
</igx-hierarchical-grid >
</div >
html コピー @use "layout.scss" ;
@use "igniteui-angular/theming" as *;
$summaries-background : #e0f3ff ;
$custom-theme : grid-summary-theme(
$background-color : $summaries-background ,
$label-color : #e41c77 ,
$result-color : black,
$pinned-border-width : 2px ,
$pinned-border-style : dotted,
$pinned-border-color : #e41c77 ,
);
:host {
--igx-grid-summaries-patch-background : #{$summaries-background };
::ng-deep {
@include css-vars($custom-theme );
}
}
scss コピー
API References
Additional Resources
Our community is active and always welcoming to new ideas.