Skip to main content

Custom Aggregate Functions

The ASPxTreeList enables you to manually implement custom aggregate functions or calculate summary values using a custom algorithm. Custom summaries allow you the following:

  • Calculate summaries against nodes that meet specific criteria;
  • Involve multiple data fields in calculations;
  • Implement complex summary functions.

To manually calculate summaries, you should set the summary item’s TreeListSummaryItem.SummaryType property to ‘Custom’ and handle the ASPxTreeList.CustomSummaryCalculate event.

Example

This example shows how to implement a custom summary calculation.

Create a summary item within the ASPxTreeList.Summary collection and customize its settings as shown below:

exCustomSummaryCalculate_1

The ASPxTreeList.CustomSummaryCalculate event is handled to sum the budgets of selected departments. Finally, set the TreeListSettingsBehavior.ProcessSelectionChangedOnServer option to true.

The image below shows the result:

exCustomSummaryCalculate_res

using DevExpress.Data;

protected void ASPxTreeList2_CustomSummaryCalculate(object sender,
TreeListCustomSummaryEventArgs e) {
    switch (e.SummaryProcess) {
        case CustomSummaryProcess.Start:
            e.Value = (int)0;
            break;
        case CustomSummaryProcess.Calculate:
            if (e.Node.Selected)
                e.Value = (int)e.Value + (int)e.Node["Budget"];
            break;
        case CustomSummaryProcess.Finalize:
            break;
    }
}