All docs
V19.2
24.1
The page you are viewing does not exist in version 24.1.
23.2
The page you are viewing does not exist in version 23.2.
23.1
The page you are viewing does not exist in version 23.1.
22.2
The page you are viewing does not exist in version 22.2.
22.1
The page you are viewing does not exist in version 22.1.
21.2
The page you are viewing does not exist in version 21.2.
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
19.1
18.2
18.1
17.2
Box
Row
Map
Vue
A newer version of this page is available. Switch to the current version.

jQuery DataGrid - summary

Specifies the options of the grid summary.

Type:

Object

A summary is a grid feature that provides a synopsis of data contained in the grid. A summary consists of several items. A summary item displays a value that is a product of applying an aggregate function to the data of a specific column.

There are two types of summary in DataGrid: group and total. The group summary is calculated on a group of data, which is segregated during grouping. To specify the items of the group summary, declare an array of objects and assign it to the summary.groupItems field.

The total summary is calculated on all data contained in the grid. To specify the items of the total summary, declare an array of objects and assign it to the summary.totalItems field.

calculateCustomSummary

Specifies a custom aggregate function. This function is called for summary items whose summaryType is "custom".

Type:

Function

Function parameters:
options:

Object

Summary information.

Object structure:
Name Type Description
component

DataGrid

The widget's instance.

groupIndex

Number

A zero-based group level. Available only when calculating group summary items.

name

String

The summary item's name.

summaryProcess

String

Indicates the stage of the summary item calculation; equals "start", "calculate" or "finalize".

totalValue any

The resulting summary item's value.

value any

If the custom summary item is calculated by a column, this field contains the value from a cell of this column. Otherwise, it contains a whole object from the data source.

This is a single function for all custom summary items. Specify a name for each item to identify them in the function.

A summary value calculation is conducted in three stages: start - the totalValue is initialized; calculate - the totalValue is modified; finalize - the totalValue is adjusted. To identify the current stage, check the value of the summaryProcess field that belongs to the function's parameter:

jQuery
JavaScript
$(function() {
    $("#dataGridContainer").dxDataGrid({
        // ...
        summary: {
            totalItems: [
                { name: "customSummary1", summaryType: "custom" },
                { name: "customSummary2", summaryType: "custom" }
            ],
            calculateCustomSummary: function(options) {
                // Calculating "customSummary1"
                if(options.name == "customSummary1") {
                    switch(options.summaryProcess) {
                        case "start":
                            // Initializing "totalValue" here
                            break;
                        case "calculate":
                            // Modifying "totalValue" here
                            break;
                        case "finalize":
                            // Assigning the final value to "totalValue" here
                            break;
                    }
                }

                // Calculating "customSummary2"
                if(options.name == "customSummary2") {
                    // ...
                    // Same "switch" statement here
                }
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-data-grid ... >
    <dxo-summary [calculateCustomSummary]="calculateSummary">
        <dxi-total-item
            name="сustomSummary1"
            summaryType="custom">
        </dxi-total-item>
        <dxi-total-item
            name="сustomSummary2"
            summaryType="custom">
        </dxi-total-item>
    </dxo-summary>
</dx-data-grid>
import { DxDataGridModule } from "devextreme-angular";
// ...
export class AppComponent {
    calculateSummary(options) {
        // Calculating "customSummary1"
        if(options.name == "customSummary1") {
            switch(options.summaryProcess) {
                case "start":
                    // Initializing "totalValue" here
                    break;
                case "calculate":
                    // Modifying "totalValue" here
                    break;
                case "finalize":
                    // Assigning the final value to "totalValue" here
                    break;
            }
        }

        // Calculating "customSummary2"
        if(options.name == "customSummary2") {
            // ...
            // Same "switch" statement here
        }
    };
}
@NgModule({
    imports: [
        // ...
        DxDataGridModule
    ],
    // ...
})

View Demo

See Also

groupItems[]

Specifies items of the group summary.

Type:

Array<Object>

Default Value: undefined

The group summary provides a synopsis of a group of data. Groups of data are formed in the process of grouping. The group summary contains several items. Each item displays a value that is a product of applying an aggregate function to a group of data.

To specify the items of the group summary, declare an array of objects, each of which contains at least two fields: column and summaryType. The column field specifies the identifier of the column that provides data for an aggregate function. The summaryType specifies the aggregate function to be applied. The following code snippet shows how to declare two summary items.

jQuery
JavaScript
$(function () {
    $("#dataGridContainer").dxDataGrid({
        // ...
        summary: {
            groupItems: [{
                column: "Age",
                summaryType: "avg"
            }, {
                column: "LastName",
                summaryType: "count"
            }]
        }
    });
});
Angular
HTML
TypeScript
<dx-data-grid ... >
    <dxo-summary>
        <dxi-group-item
            column="Age"
            summaryType="avg">
        </dxi-group-item>
        <dxi-group-item
            column="LastName"
            summaryType="count">
        </dxi-group-item>
    </dxo-summary>
</dx-data-grid>
import { DxDataGridModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxDataGridModule
    ],
    // ...
})

A group summary item may be located either in the group row or the group footer. By default, the group row holds all summary items. To locate a summary item in the group footer, set the showInGroupFooter option of this item to true.

View Demo

See Also

recalculateWhileEditing

Specifies whether to recalculate summaries while a user edits data.

Type:

Boolean

Default Value: false

skipEmptyValues

Specifies whether or not to skip empty strings, null and undefined values when calculating a summary.

Type:

Boolean

Default Value: true

Specified in the summary object, this option affects all summaries in the grid. In addition, the same option can be specified for an individual summary. It will override the global setting.

NOTE
This option does not have any effect when you use a remote data source.
NOTE
Summaries of the count type do not skip empty values regardless of the skipEmptyValues option. However, you can implement a custom summary, which skips empty values, as follows.
jQuery
JavaScript
$(function () {
    $("#dataGridContainer").dxDataGrid({
        // ...
        summary: {
            totalItems: [{
                // ...
                name: "customSummary1",
                summaryType: "custom"
            }],
            calculateCustomSummary: function (options) {
                if (options.name == "customSummary1") {
                    if (options.summaryProcess == "start") {
                        options.totalValue = 0;
                    }
                    if (options.summaryProcess == "calculate") {
                        if (e.value) {
                            options.totalValue++;
                        }
                    }
                }
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-data-grid ... >
    <dxo-summary [calculateCustomSummary]="calculateSummary">
        <dxi-total-item
            summaryType="custom"
            name="customSummary1">
        </dxi-total-item>
    </dxo-summary>
</dx-data-grid>
import { DxDataGridModule } from "devextreme-angular";
// ...
export class AppComponent {
    calculateSummary (options) {
        if (options.name == "customSummary1") {
            if (options.summaryProcess == "start") {
                options.totalValue = 0;
            }
            if (options.summaryProcess == "calculate") {
                if (e.value) {
                    options.totalValue++;
                }
            }
        }
    };
}
@NgModule({
    imports: [
        // ...
        DxDataGridModule
    ],
    // ...
})

texts

Contains options that specify text patterns for summary items.

Type:

Object

Depending on their type, summary items use one of predefined text patterns specified in the summary.texts object. For example, summary items of the "avg" type use the pattern specified by the avg field of the texts object.

By default, a summary item is located in the column that provides data for it. This column is called the "parent column". However, a summary item may be located in any other column or in a group row. To specify text patterns for such summary items, use options with the OtherColumn addition in their name. For example, summary items of the "avg" type located outside their parent column use the pattern specified by the avgOtherColumn field of the texts object.

When implementing a pattern, you can access the summary item value with applied format using position marker 0. If the summary item is placed outside its parent column, you can also access the caption of the parent column using position marker 1. Place each of these position markers within curly brackets.

totalItems[]

Specifies items of the total summary.

Type:

Array<Object>

Default Value: undefined

The total summary, which is located in the grid footer, provides a synopsis of all data contained in the grid. It contains several summary items. Each item displays a value that is a product of applying an aggregate function to the data of a specific column.

To specify the items of the total summary, declare an array of objects, each of which contains at least two fields: column and summaryType. The column field specifies the identifier of the column that provides data for an aggregate function. The summaryType specifies the aggregate function to be applied. The following code snippet shows how to declare two summary items.

jQuery
JavaScript
$(function () {
    $("#dataGridContainer").dxDataGrid({
        // ...
        summary: {
            totalItems: [{
                column: "Age",
                summaryType: "avg"
            }, {
                column: "LastName",
                summaryType: "count"
            }]
        }
    });
});
Angular
HTML
TypeScript
<dx-data-grid ... >
    <dxo-summary>
        <dxi-total-item
            column="Age"
            summaryType="avg">
        </dxi-total-item>
        <dxi-total-item
            column="LastName"
            summaryType="count">
        </dxi-total-item>
    </dxo-summary>
</dx-data-grid>
import { DxDataGridModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxDataGridModule
    ],
    // ...
})

By default, a summary item is placed in the column that provides data for it. If you need to place it in another column, assign the identifier of this column to the showInColumn option.

View Demo

See Also