Column aggregation functions

12 posts, 0 answers
  1. Jeff
    Jeff avatar
    4 posts
    Member since:
    May 2011

    Posted 09 May 2011 Link to this post

    I have a Silverlight RadGridView (Telerik v2010.3.1314.1040) being populated by a call to a user-defined stored procedure (so the columns are not known until runtime).  I'm attempting to add some aggregation functions to a couple of the columns and I am running into issues.  CountFunction, MaxFunction and MinFunction work fine, but if I try to use AverageFunction or SumFunction I get the following exception:

    No generic method 'Average' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments.
    No type arguments should be provided if the method is non-generic.
    occurred   at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
       at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
       at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilder.CreateMethodCallExpression(LambdaExpression memberSelectorExpression)
       at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilder.CreateAggregateExpression()
       at Telerik.Windows.Data.EnumerableSelectorAggregateFunction.CreateAggregateExpression(Expression enumerableExpression)
       at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.<ProjectionPropertyValueExpressions>b__3(AggregateFunction f)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)

    ... (lots more)

    The code I'm using looks something like this (the following has been simplified for readability/relevance):
           

        RadGridView gridView = // get this from calling code...
        GridViewDataColumn gridColumn = new GridViewDataColumn();     // ... lots of code to set up the column dynamically ...
        AggregateFunction fn = new SumFunction();    // MaxFunction, MinFunction, CountFunction work
        fn.Caption = "Sum: ";
        gridColumn.AggregateFunctions.Add(fn);
        gridView.ShowColumnFooters = true;

    The column in question contains an int value, but I'm getting the same issue with float, double and Decimal.

    Any help would be appreciated.

    Jeff Sumner

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 May 2011 Link to this post

    Hi Jeff,

    You should define your dynamic columns in an appropriate manner. You did not post all the code, but I assume that you haven't bind your column when you create it. This way you add an aggregate, but it does not know what to calculated because the DataMemberBinding is missing.

    I would suggest you to change your code as follows:

    GridViewDataColumn gridColumn = new GridViewDataColumn();
    gridColumn.DataMemberBinding = new Binding("StadiumCapacity");
    AggregateFunction fn = new MaxFunction();  
    fn.Caption = "Sum: ";
    gridColumn.AggregateFunctions.Add(fn);
    clubsGrid.Columns.Add(gridColumn);
    clubsGrid.ShowColumnFooters = true;

    where "StadiumCapacity" is the name of the property to be binded.

    Could you please apply this change and if you still have the problem, could you please provide your entire code for the column with aggregate?

    Regards,
    Didie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Jeff
    Jeff avatar
    4 posts
    Member since:
    May 2011

    Posted 10 May 2011 Link to this post

    I actually did bind my columns (otherwise how would MaxFunction and MinFunction work?).  Since our columns are all generated dynamically at run-time, I don't have a property in an object to bind to, our columns are represented by arrays of objects (called RowData) and accessed by column index.  If I use MaxFunction as my aggregation (or MinFunction or CountFunction), all the column data display fine and the column footer contains the appropriate value.  If I use AverageFunction or SumFunction, then the exception is thrown.

    Here's the full binding code for my column:

    GridViewDataColumn gridColumn = new GridViewDataColumn();
    gridColumn.Header = column.ColumnName;
    gridColumn.DataType = column.DataType;
    gridColumn.DataMemberBinding = new Binding(string.Format("RowData[{0}]", column.ColumnIndex));
    gridColumn.DataMemberBinding.Mode = BindingMode.OneWay;
    gridColumn.IsReadOnly = true;
    gridColumn.UniqueName = column.ColumnName;
    gridColumn.IsVisible = true;
    AggregateFunction fn = new AverageFunction();    // MaxFunction/MinFunction work!
    fn.Caption = "Avg: ";
    gridColumn.AggregateFunctions.Add(fn);

    Jeff
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 10 May 2011 Link to this post

    Hi Jeff,

     

    Sum and Average functions can not be applied if specified DataMemberBinding is not numeric. If you take a look at the provided snippet you have used String.Format and by that reason the exception occured. 
    You have to change the binding to a numeric and then everything should work as expected. 


    All the best,
    Vanya Pavlova
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Jeff
    Jeff avatar
    4 posts
    Member since:
    May 2011

    Posted 10 May 2011 Link to this post

    The string.Format() is just to create the binding PATH for the integer column value.  I'm not binding to a string.  The column values are integers and are being bound properly (they show up correctly in the grid).
  7. Jeff
    Jeff avatar
    4 posts
    Member since:
    May 2011

    Posted 10 May 2011 Link to this post

    I have a simple project that reproduces the problem, if there's some place I can send it.
  8. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 10 May 2011 Link to this post

    Hi Jeff,



    You may submit a support ticket where you can attach your application from Your Account -> GetSupport, please follow this link.



    Greetings,
    Vanya Pavlova
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 11 May 2011 Link to this post

    Hi Jeff,

     

    I have already replied in your support ticket.


    Greetings,
    Vanya Pavlova
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. sean
    sean avatar
    1 posts
    Member since:
    Jun 2010

    Posted 13 Oct 2011 Link to this post

    I got the exact  same issue  when i use column index to do data binding.
    It seems that index column binding only support  Max and Mix aggregation  but not Average and Sum

    Is this solved ? Can someone put the solution here

  11. Heiko Görig
    Heiko Görig avatar
    23 posts
    Member since:
    Jun 2012

    Posted 11 Nov 2011 Link to this post

    I have the same problem. Please fix this asap.
  12. Toufik
    Toufik avatar
    1 posts
    Member since:
    Oct 2015

    Posted 22 Oct 2015 Link to this post

    Hi All,

    I'm having the exact same issue but couldn't find a solution anywhere,

    I'm binding to a number field and data is showed correctly in the grid except for the sum where I always get 0.

    Tried a custom aggregate and got:

    Error details:
    No generic method 'SumSumFunction' on type '....ProdBalance.Sum' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 
       at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
       at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
       at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilderBase.CreateMethodCallExpression(LambdaExpression ​

  13. Petya
    Admin
    Petya avatar
    975 posts

    Posted 26 Oct 2015 Link to this post

    Hi Toufik,

    As previously mentioned in this thread, Sum function can only be applied to numeric values and the exception you're seeing will occur if you're trying to sum non-numeric types.

    Could you please verify that you are summing numeric values in the custom aggregate? If you take a look at this article, for example, the AggregateFunction adds together the values of the numeric Number property the respective object.

    In case this is not the cause for the issue, we'd appreciate it if you can open a new support ticket and send us a small demo project showing your setup.

    Regards,
    Petya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner