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

Column aggregation functions

11 Answers 216 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 09 May 2011, 04:50 PM

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

11 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 May 2011, 09:49 AM
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
0
Jeff
Top achievements
Rank 1
answered on 10 May 2011, 01:29 PM
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
0
Vanya Pavlova
Telerik team
answered on 10 May 2011, 03:10 PM
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
0
Jeff
Top achievements
Rank 1
answered on 10 May 2011, 03:20 PM
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).
0
Jeff
Top achievements
Rank 1
answered on 10 May 2011, 03:56 PM
I have a simple project that reproduces the problem, if there's some place I can send it.
0
Vanya Pavlova
Telerik team
answered on 10 May 2011, 04:00 PM
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
0
Vanya Pavlova
Telerik team
answered on 11 May 2011, 08:49 AM
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
0
sean
Top achievements
Rank 1
answered on 13 Oct 2011, 11:15 PM
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

0
Heiko Görig
Top achievements
Rank 1
answered on 11 Nov 2011, 04:24 PM
I have the same problem. Please fix this asap.
0
Toufik
Top achievements
Rank 1
answered on 22 Oct 2015, 05:29 PM

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 ​

0
Petya
Telerik team
answered on 26 Oct 2015, 03:56 PM
Hi ,

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
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Jeff
Top achievements
Rank 1
Vanya Pavlova
Telerik team
sean
Top achievements
Rank 1
Heiko Görig
Top achievements
Rank 1
Toufik
Top achievements
Rank 1
Petya
Telerik team
Share this question
or