Web Components Tree Grid Summaries

    The Ignite UI for Web Components Summaries feature in Web Components Tree Grid functions on a per-column level as group footer. Web Components IgcTreeGrid 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 IgcTreeGridComponent.

    Web Components Tree Grid Summaries Overview Example

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.

    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

    IgcTreeGridComponent 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. IgcTreeGridComponent 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.

    IgcTreeGridComponent 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 IgcTreeGridComponent 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-tree-grid id="grid1" auto-generate="false" height="800px" width="800px">
        <igc-column field="ID" header="Order ID">
        </igc-column>
        <igc-column field="Name" header="Order Product" has-summary="true">
        </igc-column>
        <igc-column field="Units" header="Units" editable="true" data-type="number" has-summary="true">
        </igc-column>
    </igc-tree-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 IgcTreeGridComponent.

    <igc-tree-grid auto-generate="false" name="treeGrid" id="treeGrid" primary-key="ID">
        <igx-column field="ID" header="Order ID" width="200px">
        </igx-column>
        <igx-column field="Name" header="Order Product" width="200px" [hasSummary]="true">
        </igx-column>
        <igx-column field="Units" width="200px" [editable]="true" [dataType]="'number'" [hasSummary]="true">
        </igx-column>
    </igc-tree-grid>
    <button id="enableBtn">Enable Summary</button>
    <button id="disableBtn">Disable Summary </button>
    html
    constructor() {
        var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGrid;
        var enableBtn = this.enableBtn = document.getElementById('enableBtn') as HTMLButtonElement;
        var disableBtn = this.disableBtn = document.getElementById('disableBtn') as HTMLButtonElement;
        treeGrid.data = this.data;
        enableBtn.addEventListener("click", this.enableSummary);
        disableBtn.addEventListener("click", this.disableSummary);
    }
    ts
    public enableSummary() {
        this.treeGrid.enableSummaries([
            {fieldName: 'Name'},
            {fieldName: 'Units'}
        ]);
    }
    public disableSummary() {
        this.treeGrid.disableSummaries(['Units']);
    }
    typescript

    Custom Tree 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 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;
        }
    }
    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 IgcSummaryResult.

    interface IgcSummaryResult {
        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 Tree Grid needs the Operate method to always return an array of IgcSummaryResult with the proper length even when the data is empty.

    And now let's add our custom summary to the column title. We will achieve that by setting the Summaries` property to the class we create below.

    <igc-tree-grid auto-generate="false" name="treeGrid" id="treeGrid" primary-key="ID">
        <igc-column field="Name" data-type="string"></igc-column>
        <igc-column field="Age" data-type="number"></igc-column>
        <igc-column field="Title" data-type="string" has-summary="true" id="column1"></igc-column>
    </igc-tree-grid>
    html
    constructor() {
        var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGrid;
        var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
        treeGrid.data = this.data;
        column1.summaries = this.mySummary;
    }
    ts
    export class TreeGridComponent implements OnInit {
        mySummary = MySummary;
    }
    typescript

    Custom summaries, which access all data

    Now you can access all Tree 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 MySummary extends IgcNumberSummaryOperand {
        constructor() {
            super();
        }
        operate(columnData: any[], allGridData = [], fieldName?): IgcSummaryResult[] {
            const result = super.operate(allData.map(r => r[fieldName]));
            result.push({ key: 'totalOnPTO', label: 'Employees On PTO', summaryResult: this.count(allData.filter((rec) => rec['OnPTO']).map(r => r[fieldName])) });
            return result;
        }
    }
    typescript

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    Summary Template

    Summary targets the column summary providing as a context the column summary results.

    <igc-column id="column" has-summary="true">
    </igc-column>
    html
    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>
        `;
    }
    ts

    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.

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    Ignite UI for Web Components | CTA Banner

    Disabled Summaries

    The disabled-summaries property provides precise per-column control over the Web Components Tree Grid summary feature. This property enables users to customize the summaries displayed for each column in the IgcTreeGrid, 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 IgcTreeGrid'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 Tree 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>
    html

    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.

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    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;
        }
    typescript
    <igc-column id="column"></igx-column>
    html
    constructor() {
        var column = this.column = document.getElementById('column') as IgcColumnComponent;
        column.summaryFormatter = this.dateSummaryFormat;
    }
    ts

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    Child Summaries

    The IgcTreeGridComponent supports separate summaries for the root nodes and for each nested child node level. Which summaries are shown is configurable using the summaryCalculationMode property. The child level summaries can be shown before or after the child nodes using the summaryPosition property. Along with these two properties the IgcTreeGridComponent exposes and showSummaryOnCollapse property which allows you to determine whether the summary row stays visible when the parent node that refers to is collapsed.

    The available values of the summaryCalculationMode property are:

    • RootLevelOnly - Summaries are calculated only for the root level nodes.
    • ChildLevelsOnly - Summaries are calculated only for the child levels.
    • RootAndChildLevels - Summaries are calculated for both root and child levels. This is the default value.

    The available values of the summaryPosition property are:

    • Top - The summary row appears before the list of child rows.
    • Bottom - The summary row appears after the list of child rows. This is the default value.

    The showSummaryOnCollapse property is boolean. Its default value is set to false, which means that the summary row would be hidden when the parent row is collapsed. If the property is set to true the summary row stays visible when parent row is collapsed.

    The summaryPosition property applies only for the child level summaries. The root level summaries appear always fixed at the bottom of the IgcTreeGridComponent.

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    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:

    <igc-tree-grid class="grid"></igc-tree-grid>
    html

    Then set the related CSS properties for that class:

    .grid {
        --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;
    }
    css

    Demo

    EXAMPLE
    DATA
    TS
    HTML
    CSS

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.