Web Components Hierarchical Grid Summaries
The Ignite UI for Web Components Summaries feature in Web Components Hierarchical Grid functions on a per-column level as group footer. Web Components IgcHierarchicalGrid 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 IgcHierarchicalGridComponent
.
Web Components 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
IgcHierarchicalGridComponent
summaries can also be enabled on a per-column level in Ignite UI for Web Components, which means that you can activate it only for columns that you need. IgcHierarchicalGridComponent
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:
- Contar
Para number
e currency
percent
tipos de dados, as seguintes funções estão disponíveis:
- Contar
- Mínimo
- Máx.
- Média
- Soma
Para date
o tipo de dados, as seguintes funções estão disponíveis:
- Contar
- Mais antigo
- Mais recente
Todos os tipos de dados de coluna disponíveis podem ser encontrados no tópico oficial Tipos de coluna.
IgcHierarchicalGridComponent
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 IgcHierarchicalGridComponent
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
.
<igc-hierarchical-grid auto-generate="false" name="hierarchicalGrid" id="hierarchicalGrid" primary-key="ID">
<igc-column field="Artist" header="Artist" has-summary="true"> </igc-column>
<igc-column field="Photo" header="Photo" data-type="image"> </igc-column>
<igc-column field="Debut" header="Debut" has-summary="true"> </igc-column>
<igc-column field="GrammyNominations" header="Grammy Nominations" data-type="number" has-summary="true"> </igc-column>
<igc-column field="GrammyAwards" header="Grammy Awards" data-type="number" has-summary="true"> </igc-column>
<igc-row-island child-data-key="Albums" auto-generate="false">
<igc-column field="Album" header="Album" data-type="string"> </igc-column>
<igc-column field="LaunchDate" header="Launch Date" data-type="date"> </igc-column>
<igc-column field="BillboardReview" header="Billboard Review" data-type="number" has-summary="true"> </igc-column>
<igc-column field="USBillboard200" header="US Billboard 200" data-type="number" has-summary="true"> </igc-column>
</igc-row-island>
</igc-hierarchical-grid>
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 IgcHierarchicalGridComponent
.
<igc-hierarchical-grid auto-generate="false" name="hierarchicalGrid" id="hierarchicalGrid" primary-key="ID">
<igc-column field="Artist" header="Artist" has-summary="true"> </igc-column>
<igc-column field="Photo" header="Photo" data-type="image"> </igc-column>
<igc-column field="Debut" header="Debut" has-summary="true"> </igc-column>
<igc-column field="GrammyNominations" header="Grammy Nominations" data-type="number" has-summary="true"> </igc-column>
<igc-column field="GrammyAwards" header="Grammy Awards" data-type="number" has-summary="true"> </igc-column>
</igc-hierarchical-grid>
<button id="enableBtn">Enable Summary</button>
<button id="disableBtn">Disable Summary </button>
constructor() {
var hierarchicalGrid = this.hierarchicalGrid = document.getElementById('hierarchicalGrid') as IgcHierarchicalGrid;
var enableBtn = this.enableBtn = document.getElementById('enableBtn') as HTMLButtonElement;
var disableBtn = this.disableBtn = document.getElementById('disableBtn') as HTMLButtonElement;
hierarchicalGrid.data = this.data;
enableBtn.addEventListener("click", this.enableSummary);
disableBtn.addEventListener("click", this.disableSummary);
}
public enableSummary() {
this.hierarchicalGrid.enableSummaries([
{fieldName: 'GrammyNominations'},
{fieldName: 'GrammyAwards'}
]);
}
public disableSummary() {
this.hierarchicalGrid.disableSummaries(['GrammyNominations']);
}
Custom Hierarchical Grid Summaries
Se essas funções não atenderem aos seus requisitos, você pode fornecer um resumo personalizado para as colunas específicas.
In order to achieve this you have to override one of the base classes IgcSummaryOperand
, IgcNumberSummaryOperand
or IgcDateSummaryOperand
according to the column data type and your needs. This way you can redefine the existing function or you can add new functions. IgcSummaryOperand
class provides the default implementation only for the count
method. IgcNumberSummaryOperand
extends IgcSummaryOperand
and provides implementation for the Min
, Max
, Sum
and Average
. IgcDateSummaryOperand
extends IgcSummaryOperand
and additionally gives you Earliest
and Latest
.
import { IgcSummaryResult, IgcSummaryOperand, IgcNumberSummaryOperand, IgcDateSummaryOperand } from 'igniteui-webcomponents-grids';
class MySummary extends IgcNumberSummaryOperand {
constructor() {
super();
}
operate(data?: any[]): IgcSummaryResult[] {
const result = super.operate(data);
result.push({
key: 'test',
label: 'Test',
summaryResult: data.filter(rec => rec > 10 && rec < 30).length
});
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 IgcSummaryResult
.
interface IgcSummaryResult {
key: string;
label: string;
summaryResult: any;
}
e tomar parâmetros opcionais para calcular os resumos. Consulte a seção Resumos personalizados, que acessam todos os dados abaixo.
[!Note] In order to calculate the summary row height properly, the Hierarchical Grid needs the
Operate
method to always return an array ofIgcSummaryResult
with the proper length even when the data is empty.
And now let's add our custom summary to the column GrammyAwards
. We will achieve that by setting the Summaries` property to the class we create below.
<igc-hierarchical-grid auto-generate="false" name="hierarchicalGrid" id="hierarchicalGrid" primary-key="ID">
<igc-column field="Artist" header="Artist" has-summary="true"> </igc-column>
<igc-column field="Photo" header="Photo" data-type="image"> </igc-column>
<igc-column field="Debut" header="Debut" has-summary="true"> </igc-column>
<igc-column field="GrammyNominations" header="Grammy Nominations" data-type="number" has-summary="true"> </igc-column>
<igc-column field="GrammyAwards" header="Grammy Awards" data-type="number" has-summary="true" id="grammyAwards"> </igc-column>
</igc-hierarchical-grid>
constructor() {
var hierarchicalGrid = this.hierarchicalGrid = document.getElementById('hierarchicalGrid') as IgcHierarchicalGrid;
var grammyAwards = this.grammyAwards = document.getElementById('grammyAwards') as IgcColumnComponent;
hierarchicalGrid.data = this.data;
grammyAwards.summaries = this.mySummary;
}
export class HierarchicalGridComponent implements OnInit {
mySummary = MySummary;
}
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 - fornece uma matriz que contém os valores apenas para a coluna atual
- allGridData - fornece a fonte de dados da grade completa
- fieldName - campo da coluna atual
class MySummary extends IgcNumberSummaryOperand {
constructor() {
super();
}
operate(columnData: any[], allGridData = [], fieldName?): IgcSummaryResult[] {
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;
}
}
Summary Template
Summary
tem como alvo o resumo da coluna, fornecendo como contexto os resultados do resumo da coluna.
<igc-column id="column" has-summary="true">
</igc-column>
constructor() {
var column = this.column = document.getElementById('column') as IgcColumnComponent;
column.summaryTemplate = this.summaryTemplate;
}
public summaryTemplate = (ctx: IgcSummaryTemplateContext) => {
return html`
<span> My custom summary template</span>
<span>${ ctx.implicit[0].label } - ${ ctx.implicit[0].summaryResult }</span>
`;
}
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 disabled-summaries
property provides precise per-column control over the Web Components Hierarchical Grid summary feature. This property enables users to customize the summaries displayed for each column in the IgcHierarchicalGrid, 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 IgcHierarchicalGrid's summaries to changing application states or user actions.
The following examples illustrate how to use the disabled-summaries
property to manage summaries for different columns and exclude specific default and custom summary types in the Web Components Hierarchical Grid:
<!-- Disable default summaries -->
<igc-column
field="UnitPrice"
header="Unit Price"
data-type="number"
has-summary="true"
disabled-summaries="['count', 'sum', 'average']"
>
</igc-column>
<!-- Disable custom summaries -->
<igc-column
field="UnitsInStock"
header="Units In Stock"
data-type="number"
has-summary="true"
summaries="discontinuedSummary"
disabled-summaries="['discontinued', 'totalDiscontinued']"
>
</igc-column>
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 disabled-summaries
property.
At runtime, summaries can also be dynamically disabled using the disabled-summaries
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 dateSummaryFormat(summary: IgcSummaryResult, summaryOperand: IgcSummaryOperand): string {
const result = summary.summaryResult;
if (summaryOperand instanceof IgcDateSummaryOperand && summary.key !== "count" && result !== null && result !== undefined) {
const format = new Intl.DateTimeFormat("en", { year: "numeric" });
return format.format(new Date(result));
}
return result;
}
<igc-column id="column"></igx-column>
constructor() {
var column = this.column = document.getElementById('column') as IgcColumnComponent;
column.summaryFormatter = this.dateSummaryFormat;
}
Keyboard Navigation
As linhas de resumo podem ser navegadas com as seguintes interações de teclado:
- PARA CIMA- navega uma célula para cima.
- PARA BAIXO- navega uma célula para baixo.
- ESQUERDA- navega uma célula para a esquerda.
- DIREITA- navega uma célula para a direita.
- CTRL + ESQUERDA ou HOME- navega para a célula mais à esquerda.
- CTRL + DIREITA ou END- navega para a célula mais à direita.
Styling
Além dos temas predefinidos, a grade pode ser ainda mais personalizada ao definir algumas das propriedades CSS disponíveis. Caso você queira alterar algumas das cores, precisa definir uma classe para a grade primeiro:
<igc-hierarchical-grid id="hierarchicalGrid"></igc-hierarchical-grid>
Em seguida, defina as propriedades CSS relacionadas para essa classe:
#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
Nossa comunidade é ativa e sempre acolhedora para novas ideias.