[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]ASP.NET WebForms Controls
   Getting Started
  [Collapse]Grid View
   [Expand]Product Information
    Getting Started
    [Expand]Binding to Data
    [Expand]Data Representation Basics
    [Expand]Focus and Navigation
    [Expand]Data Editing
    [Collapse]Data Shaping and Manipulation
     [Collapse]Data Summaries
       Predefined Aggregate Functions
       Group Summary
       Total Summary
       Obtain Summary Values
       Custom Aggregate Functions
      Cell Merging
    [Expand]Data Formatting
    [Expand]Master-Detail Relationship
     Appearance Customization
     Save and Restore Layout
    ASPxGridView Designer
   [Expand]Visual Elements
   [Expand]Member Tables
   [Expand]ASPxGridView - Animated Images
  [Expand]Tree List
  [Expand]Card View
  [Expand]Chart Control
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Site Navigation and Layout
  [Expand]HTML Editor
  [Expand]Vertical Grid
  [Expand]Data Editors
  [Expand]Docking and Popups
  [Expand]File Management
  [Expand]Data and Image Navigation
  [Expand]Multi-Use Site Controls
  [Expand]Spell Checker
  [Expand]Query Builder
 [Expand]ASP.NET MVC Extensions
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Custom Aggregate Functions

Total summaries and group summaries provide five predefined aggregate functions. These functions allow you to calculate:

  • the number of data rows;
  • the maximum and minimum values;
  • the sum and the average value.

ASPxGridView provides the ASPxGridBase.CustomSummaryCalculate event that enables you to implement custom aggregate functions or calculate summary values using a custom algorithm. Custom summaries allow you to:

  • Calculate summaries against records that meet specific criteria
  • Involve multiple data fields in calculations
  • Implement complex summary functions (e.g. the standard deviation of a population), etc.

Expanded General Information

To calculate a summary manually:

The ASPxGridBase.CustomSummaryCalculate event fires for each data row involved in summary calculation. When calculating a total summary value, the event is raised for each data row. When calculating a group summary value, the event fires for each data row within a group. To enable you to perform any initialization and finalization, the event is raised before and after the processing of rows.

The summary calculation consists of three stages.

  • Initialization

    The CustomSummaryCalculate event is raised once and the SummaryProcess property is set to CustomSummaryProcess.Start. At this stage, you can initialize summary values (e.g. reset internal counters).

  • Calculation

    The CustomSummaryCalculate event fires multiple times, once for each data row in a grid or group. The SummaryProcess property is set to CustomSummaryProcess.Calculate. At this stage you should accumulate summaries.

    The event parameter's properties allow the processed row and its values to be obtained.

  • Finalization

    The CustomSummaryCalculate event is raised once and the SummaryProcess property is set to CustomSummaryProcess.Finalize. At this point, calculate a final summary value and assign it to the event parameter's TotalValue property.

To determine the current stage, use the event parameter's SummaryProcess property.

To skip the Calculation stage and calculate a custom summary at the Initialization or Finalization stage, set the event parameter's TotalValueReady property to true at the Initialization stage. This automatically skips the Calculation stage and the Finalization stage starts immediately.

Expanded Example

This example shows how to implement a custom summary calculation.

Create a summary item within the ASPxGridView.TotalSummary collection, and customize its settings, as shown below:

The ASPxGridBase.CustomSummaryCalculate event is handled to sum the budgets of selected departments.

Note that in order to process selection changes on the server side, you can either set the ASPxGridBehaviorSettings.ProcessSelectionChangedOnServer property to true or handle the ASPxClientGridView.SelectionChanged client event, and call the ASPxClientGridView.PerformCallback client method.


The ASPxGridView.EnableRowsCache property should be set to false.

The image below shows the result:

Is this topic helpful?​​​​​​​