This is a migrated thread and some comments may be shown as answers.

Aggregate Functions for Multiple Data

5 Answers 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 14 Mar 2011, 07:05 PM
Is there a way to use Aggregate Functions when multiple data values are used in the column? In our scenario, we have two values in each column and need two separate sum values in the footer. 

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

Sort by
0
Vlad
Telerik team
answered on 15 Mar 2011, 07:47 AM
Hello,

 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
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Mike
Top achievements
Rank 1
answered on 15 Mar 2011, 03:42 PM
We have reviewed the Custom Aggregate demo but it appears to work with a single double source (Func<TSource, double>).  The column is databinding to a object with two double values.   We need to a column to have two SumFunctions (one for Value1 and one for Value2).
0
Mike
Top achievements
Rank 1
answered on 15 Mar 2011, 04:13 PM
thanks for the reply.    I tried the following as instead of a double, I have a complex object. Where CorpMultiDataModel is a class containing 2 decimals.  When we try to use this we get an error that said “No Sum” method available.  Do you have an example of an agregate function using a complex object instead of a double?

 

    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;

    }

0
Mike
Top achievements
Rank 1
answered on 17 Mar 2011, 02:16 PM
hey guys any other guidance here (See below)?

Thanks alot , you have been a great help on the past couple issues.
0
Maya
Telerik team
answered on 18 Mar 2011, 01:59 PM
Hi Mike,

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.
 

Kind regards,
Maya
the Telerik team
Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Mike
Top achievements
Rank 1
Maya
Telerik team
Share this question
or