Class CustomAggregators
Provides methods that manipulate custom aggregators.
Namespace: DevExtreme.AspNet.Data.Aggregation
Assembly: DevExtreme.AspNet.Data.dll
Syntax
public static class CustomAggregators
Remarks
When implementing a custom data aggregator, derive it from the Aggregator<T>
class as shown in the following example. The custom aggregator in it calculates total sales:
class TotalSalesAggregator<T> : Aggregator<T> {
decimal _total = 0;
public TotalSalesAggregator(IAccessor<T> accessor)
: base(accessor) {
}
public override void Step(T container, string selector) {
var quantity = Convert.ToInt32(Accessor.Read(container, "Quantity"));
var unitPrice = Convert.ToDecimal(Accessor.Read(container, "UnitPrice"));
var discount = Convert.ToDecimal(Accessor.Read(container, "Discount"));
_total += quantity * unitPrice * (1 - discount);
}
public override object Finish() {
return _total;
}
}
Then, register the aggregator under a string identifier at the application's start (for instance, in Global.asax or Startup.cs):
CustomAggregators.RegisterAggregator("totalSales", typeof(TotalSalesAggregator<>));
Important
Custom aggregators are ignored if the LINQ provider groups data and calculates summaries. Set RemoteGrouping to false
for custom aggregators to apply.
Methods
| Improve this DocRegisterAggregator(String, Type)
Registers a custom aggregator.
Declaration
public static void RegisterAggregator(string summaryType, Type aggregatorType)
Parameters
Type | Name | Description |
---|---|---|
String | summaryType | The aggregator's string identifier. |
Type | aggregatorType | The aggregator's type declaration without the generic type parameter T. |