We implemented a custom GridViewDataColumn class that accepts a DataMemberBinding of an object with multiple properties. The CreateCellElement methods creates the textblocks with the appropriate binding to the child properties (Value1 and Value2). Is it possible to create an aggregate function that totals the sum of Value1 and Value2 into two separate values that can be rendered in the Aggregate Function's format string?
5 Answers, 1 is accepted
You will need to write your own custom aggregate function to handle such cases. Please check this demo for more info about custom aggregate functions
Best wishes,Vlad
the Telerik team
public class BudgetAgregateFunction : EnumerableAggregateFunction
{
protected override string AggregateMethodName
{
get
{
return "Sum";
}
}
protected override Type ExtensionMethodsType
{
get
{
return typeof(BudgetSum);
}
}
}
public static class BudgetSum
{
public static CorpMultiDataModel Sum<TSource>(IEnumerable<TSource> source, Func<TSource, CorpMultiDataModel> complex)
{
CorpMultiDataModel result = new CorpMultiDataModel();
IEnumerable<CorpMultiDataModel> values = from i in source select complex(i);
foreach(CorpMultiDataModel item in values)
{
result.Value1+=result.Value1;
result.Value2+=result.Value2;
}
result.Value2 = result.Value2/values.Count();
return result;
}
Thanks alot , you have been a great help on the past couple issues.
May I suggest you yet another approach ? You may use the generic AggregateExpression instead. You may take a look at this forum thread for a reference. However, it depends entirely to your particular settings and requirements which approach to take.
Maya
the Telerik team