|
1 | 1 | --- |
2 | 2 | layout: post |
3 | 3 | title: Aggregates in Blazor DataGrid Component | Syncfusion |
4 | | -description: Checkout and learn here all about Aggregates in the Syncfusion Blazor DataGrid component and much more. |
| 4 | +description: Learn how to configure and display aggregates in Syncfusion Blazor DataGrid using templates for footer, group footer, and caption. |
| 5 | + |
5 | 6 | platform: Blazor |
6 | 7 | control: DataGrid |
7 | 8 | documentation: ug |
8 | 9 | --- |
9 | 10 |
|
10 | 11 | # Aggregates in Blazor DataGrid |
11 | 12 |
|
12 | | -The Aggregates feature in the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid allows you to display aggregate values in the footer, group footer, and group caption of the Grid. With this feature, you can easily perform calculations on specific columns and show summary information.This feature can be configured using the **GridAggregates** component.To represent an aggregate column, you need to specify the minimum required properties, such as [Field](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Field) and [Type](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Type). |
| 13 | +The aggregates feature in the Syncfusion Blazor DataGrid displays summary values in the footer, group footer, and group caption. It enables computing summary information for specific columns and presenting it at key locations in the DataGrid. Configure aggregates with the GridAggregates component. For each aggregate column, specify at least the [Field](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Field) and [Type](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Type) properties. |
13 | 14 |
|
14 | | -**Displaying aggregate values** |
| 15 | +For customized rendering, use aggregate templates and access values via AggregateTemplateContext (for example, **Sum, Average, Min, Max, Count, TrueCount**, and **FalseCount**). See: [AggregateTemplateContext](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.AggregateTemplateContext.html) and [AggregateType](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.AggregateType.html). |
15 | 16 |
|
16 | | -By default, the aggregate values are displayed in the footer, group, and caption cells of the Grid. However, you can choose to display the aggregate value in any of these cells by using the following properties: |
| 17 | +**Displaying aggregate values** |
17 | 18 |
|
18 | | -* [FooterTemplate](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_FooterTemplate): Use this property to display the aggregate value in the footer cell. You can define a custom template to format the aggregate value as per your requirements. |
| 19 | +By default, aggregate values can be shown in the footer, group footer, and group caption cells. Control where and how the values are displayed using these properties: |
19 | 20 |
|
20 | | -* [GroupFooterTemplate](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_GroupFooterTemplate): Use this property to display the aggregate value in the group footer cell. Similar to the footerTemplate, you can provide a custom template to format the aggregate value. |
| 21 | +* [FooterTemplate](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_FooterTemplate): Display and format the aggregate value in the footer cell with a custom template. |
| 22 | +* [GroupFooterTemplate](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_GroupFooterTemplate): Display and format the aggregate value in the group footer cell with a custom template. |
| 23 | +* [GroupCaptionTemplate](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_GroupCaptionTemplate): Display and format the aggregate value in the group caption cell with a custom template. |
21 | 24 |
|
22 | | -* [GroupCaptionTemplate](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_GroupCaptionTemplate): Use this property to display the aggregate value in the group caption cell. You can define a custom template to format the aggregate value. |
| 25 | +N> Group footer and group caption aggregates appear when grouping is enabled and data is grouped. |
23 | 26 |
|
24 | 27 | {% tabs %} |
25 | 28 | {% highlight razor tabtitle="Index.razor" %} |
@@ -125,27 +128,24 @@ By default, the aggregate values are displayed in the footer, group, and caption |
125 | 128 | {% endhighlight %} |
126 | 129 | {% endtabs %} |
127 | 130 |
|
128 | | -{% previewsample "https://blazorplayground.syncfusion.com/embed/hZrACXUDUeyrfGOs?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %} |
| 131 | +{% previewsample "https://blazorplayground.syncfusion.com/embed/BtrIDaLdIjQgCsmJ?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %} |
129 | 132 |
|
130 | | -> * When using local data, the total summary is calculated based on the entire dataset available in the Grid. The aggregate values will reflect calculations across all the rows in the Grid. |
131 | | -> * When working with remote data, the total summary is calculated based on the current page records. This means that if you have enabled pagination and are displaying data in pages, the aggregate values in the footer will represent calculations only for the visible page. |
| 133 | +> - With local data, total summaries are calculated over the entire bound dataset. Footer aggregates reflect calculations across all rows. |
| 134 | +> - With remote data, footer summaries typically reflect only the current page unless the data adaptor or server returns total summaries. When paging is enabled, the footer shows aggregates for visible page records by default. |
132 | 135 |
|
133 | 136 | ## Built-in aggregate types |
134 | 137 |
|
135 | | -The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid provides several built-in aggregate types that can be specified in the [Type](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Type) property to configure an aggregate column. |
| 138 | +The Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid provides several built-in aggregate types that can be assigned via the [Type](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Type) property on an aggregate column. |
136 | 139 |
|
137 | 140 | The available built-in aggregate types are : |
138 | 141 |
|
139 | | -* **Sum:** Calculates the sum of the values in the column. |
140 | | - |
141 | | -* **Average:** Calculates the average of the values in the column. |
142 | | -* **Min:** Finds the minimum value in the column. |
143 | | -* **Max:** Finds the maximum value in the column. |
144 | | -* **Count:** Counts the number of values in the column. |
145 | | -* **TrueCount:** Counts the number of true values in the column. |
146 | | -* **FalseCount:** Counts the number of false values in the column. |
147 | | - |
148 | | -Here is an example that demonstrates how to use built-in aggregates types in the Grid: |
| 142 | +* **Sum**: Calculates the sum of values in the column. |
| 143 | +* **Average**: Calculates the average of values in the column. |
| 144 | +* **Min**: Finds the minimum value in the column. |
| 145 | +* **Max**: Finds the maximum value in the column. |
| 146 | +* **Count**: Counts the number of values in the column. |
| 147 | +* **TrueCount**: Counts the number of true values in the column. |
| 148 | +* **FalseCount**: Counts the number of false values in the column. |
149 | 149 |
|
150 | 150 | {% tabs %} |
151 | 151 | {% highlight razor tabtitle="Index.razor" %} |
@@ -289,11 +289,16 @@ Here is an example that demonstrates how to use built-in aggregates types in the |
289 | 289 | {% endhighlight %} |
290 | 290 | {% endtabs %} |
291 | 291 |
|
292 | | -{% previewsample "https://blazorplayground.syncfusion.com/embed/LNrgCDAjUmunNwOO?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %} |
| 292 | +{% previewsample "https://blazorplayground.syncfusion.com/embed/rDVeturxIXlkRbPO?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %} |
293 | 293 |
|
294 | | -> * Multiple types for a column are supported only when one of the aggregate templates is used. |
295 | | -> * The aggregate values must be accessed inside the template using their corresponding [Type](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Type) name. |
| 294 | +> - Multiple aggregate types for a single column are supported only when one of the aggregate templates is used. |
| 295 | +> - Access aggregate values inside the template using the corresponding [Type](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridAggregateColumn.html#Syncfusion_Blazor_Grids_GridAggregateColumn_Type) name (for example, Sum, Average, Min, Max, Count, TrueCount, FalseCount). |
| 296 | +> - Use the Format property (for example, C2 or d) to apply culture-aware currency and date formatting to aggregate values. |
296 | 297 |
|
297 | 298 | ## See also |
298 | 299 |
|
299 | | -* [Handling Aggregates in Custom Adaptor](https://blazor.syncfusion.com/documentation/datagrid/custom-binding#handling-aggregates-in-custom-adaptor) |
| 300 | +* [Handling aggregates in custom adaptor](https://blazor.syncfusion.com/documentation/datagrid/connecting-to-adaptors/custom-adaptor#handling-aggregates-operation) |
| 301 | +* [AggregateTemplateContext API reference](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.AggregateTemplateContext.html) |
| 302 | +* [AggregateType enumeration](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.AggregateType.html) |
| 303 | +* [Grouping in DataGrid](https://blazor.syncfusion.com/documentation/datagrid/grouping) |
| 304 | +* [Column templates](https://blazor.syncfusion.com/documentation/datagrid/column-template) |
0 commit comments