Custom Aggregate Functions
The Telerik UI for WPF suite comes with its own data engine that is used in the RadGridView
control. The engine provides a set of predefined aggregate functions that can be applied over the data - count, sum, max, average, etc.
This article describes how to implement custom aggregate functions by inheriting the EnumerableAggregateFunction
EnumerableSelectorAggregateFunction
classes, and also the generic AggregateFunction<TElement, TResult>
class.
Implementing Custom EnumerableAggregateFunction
The EnumerableAggregateFunction
represents a function that uses aggregate extension methods to return a specific result. Examples of Telerik built-in functions using this class are - CountFunction
, FirstFunction
and LastFunction
.
To implement your own aggregate with custom behavior, inherit the EnumerableAggregateFunction
and override its AggregateMethodName
and ExtensionMethodsType
members.
The ExtensionMethodsType
tells the type of the static class that holds the methods used for aggregation.
The AggregateMethodName
returns the name of the aggregation method from the static class.
Implementing a static class that holds the aggregation functions
Implementing a custom function that calculates the median of the items
The Club model used to populate the ItemsSource of RadGridView
Adding the function in the AggregateFunctions collection of RadGridView's columns
Implementing Custom EnumerableSelectorAggregateFunction
The EnumerableSelectorAggregateFunction
represents a function that uses a specific field from the data items in order to apply calculations over the data set. Examples of Telerik built-in functions using this class are - AverageFunction
, MaxFunction
, MinFunction
, SumFunction
.
To implement your own aggregate with custom behavior, inherit the EnumerableSelectorAggregateFunction
and override its AggregateMethodName
and ExtensionMethodsType
members.
The ExtensionMethodsType
tells the type of the static class that holds the methods used for aggregation.
The AggregateMethodName
returns the name of the aggregation method from the static class.
Implementing a static class that holds the aggregation functions
Implementing a custom function that calculates the median of the items
Adding the function in the AggregateFunctions collection of RadGridView's columns
Using Generic Aggregate Function
To implement a generic aggregate function, you can use the AggregateFunction<TElement, TResult>
class and set its AggregationExpression
property.