Total Summary
- 2 minutes to read
The total summary represents a value of an aggregate function calculated over all data rows displayed within a View. Total summaries are displayed within the Summary Panel or Fixed Summary Panel, provided that the DataViewBase.ShowTotalSummary and DataViewBase.ShowFixedTotalSummary options are enabled, respectively. Summaries displayed within the Fixed Summary Panel are not horizontally scrolled, they are always visible onscreen, regardless of the corresponding column's position and visibility.
Table Views and TreeList Views display Summary panels at the bottom.
#Displaying Total Summaries
Total summaries are represented by GridSummaryItem objects. The grid stores its total summaries within the GridControl.TotalSummary collection.
The code below shows how to create total summary items.
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem FieldName="ProductName" SummaryType="Count" />
<dxg:GridSummaryItem DisplayFormat="Max: {0:c2}" FieldName="UnitPrice" SummaryType="Max" />
<dxg:GridSummaryItem DisplayFormat="Avg: {0:c2}" FieldName="UnitPrice" SummaryType="Average" />
</dxg:GridControl.TotalSummary>
To display a total summary in code, create a new instance of the GridSummaryItem class, specify its SummaryItemBase.FieldName and SummaryItemBase.SummaryType properties, and add it to the GridControl.TotalSummary collection. To display a summary item within the Fixed Summary Panel, align it to the Left or Right using the SummaryItemBase.Alignment property.
using DevExpress.Data;
// ...
grid.TotalSummary.Add(SummaryItemType.Count, "ProductName");
grid.TotalSummary.Add(SummaryItemType.Max, "UnitPrice").DisplayFormat = "Max: {0:c2}";
grid.TotalSummary.Add(SummaryItemType.Average, "UnitPrice").DisplayFormat = "Avg: {0:c2}";
End-users can display total summaries via the Summary Panel's popup menu. To learn more, see Customizing Summaries.
#Obtaining Summary Values
To obtain a total summary value, use the DataControlBase.GetTotalSummaryValue method. To obtain a list of total summary items displayed within a column, use the column's ColumnBase.TotalSummaries property.
To determine whether or not a column displays a total summary(s), use the ColumnBase.HasTotalSummaries property.
Use the DataViewBase.FixedSummariesLeft and DataViewBase.FixedSummariesRight properties to obtain total summaries displayed within the Fixed Summary Panel and aligned to the Left or Right, respectively.