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

GridViewExpressionColumn and Aggregating

3 Answers 165 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 05 Sep 2016, 09:06 AM

Hi,

How can I add a sumfunction to a GridViewExpression column?
for a GridViewDataColumn I simply add:

<telerik:GridViewDataColumn.AggregateFunctions>
            <telerik:SumFunction />
</telerik:GridViewDataColumn.AggregateFunctions>

and it works 100%, but when I do it for the same for GridViewExpressionColumn:

<telerik:GridViewExpressionColumn.AggregateFunctions>
            <telerik:SumFunction />
 </telerik:GridViewExpressionColumn.AggregateFunctions>

I get an error "No Generic method 'Sum' on type 'System.linq.Enumerable' is compatible with the supplied type arguments".
The data in GridViewDataColumns is of Type Decimal, do i need to set the type of the expression column? if so, how?

thanks.

regards,
Matthew

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 06 Sep 2016, 01:26 PM
Hello Matthew,

I'm afraid you cannot explicitly set a data type for a GridViewExpressionColumn, but you could define a generic AggregateFunction as documented in this article. I'm attaching a sample project to better demonstrate how you can implement this.

Please give this a try and let me know if such an approach would work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Matthew
Top achievements
Rank 1
answered on 06 Sep 2016, 02:33 PM

Hello Dilyan,

Thanks. Your solution works for me, but please help me understand:
If you have numeric values in the GridViewExpressionColumn, why does the standard sumfunction not work?

Thanks.

regards,
Matthew

0
Dilyan Traykov
Telerik team
answered on 07 Sep 2016, 01:02 PM
Hello Matthew,

The reason the standard sum function does not work when using the GridViewExpressionColumn is that the function is not passed the calculated numeric values, but rather the whole bound objects as that is simply the way this type of column works.

Thus, it cannot operate correctly without an explicit AggregationExpression being provided, which is the case of the custom sum function from the project in my previous reply.

I hope that this clarifies things for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or