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

[Solved] How to use Genreric AggregateFunction ?

9 Answers 510 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
stauder
Top achievements
Rank 1
stauder asked on 07 Feb 2011, 02:39 PM
Hi,

I have a GridViewExpressionColumn and I want to calculate the sum of  the elements of the column.
I think I have to use a Generic AggregateFunction but I can't figure out  how to use it, and I can't find any example. Can anyone provide a simple example on how to use Generic AggregateFunction for a GridViewExpressionColumn ?

Thank you.

9 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 07 Feb 2011, 02:48 PM
Hi stauder,

I am sending you a sample project illustrating how you may benefit from the Generic AggregateFunction. Let me know if you need any further assistance.
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
stauder
Top achievements
Rank 1
answered on 07 Feb 2011, 03:40 PM
Sorry if I was unclear but I want to use AggregateFunctions on a calculated field  (GridViewExpressionColumn). The SumFunction doesn't work for this and I've read on another post on this forum that I should use a Generic AggregateFunction. I've seen the documentation of Generic AggregateFunction but no example is provided :(

Thanks for your help.
0
Maya
Telerik team
answered on 07 Feb 2011, 04:21 PM
Hello stauder,

You may extend the provided example by setting the aggregate expression as an aggregate function for a GridViewExpressionColumn. I am sending you the updated sample.
 

Regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
stauder
Top achievements
Rank 1
answered on 08 Feb 2011, 09:40 AM
Thanks for your answer, but it's still not what I want.

Here's what I wrote
<telerik:GridViewExpressionColumn Header="Calculated field" UniqueName="Calculated" >
    <telerik:GridViewExpressionColumn.AggregateFunctions>
        <telerik:SumFunction Caption="Total: " />
    </telerik:GridViewExpressionColumn.AggregateFunctions>
</telerik:GridViewExpressionColumn>
But I don't know what to add to make the SumFunction to work. I could not find any sample of AggregateFunction on a GridViewExpressionColumn.

Thanks in advance
0
Maya
Telerik team
answered on 08 Feb 2011, 05:40 PM
Hi stauder,

For the time being the only way for defining aggregates for the GridViewExpressionColumn is to follow the approach demonstrated in the sample project - to create a generic AggregateFunction and add it in the AggregateFunctions collection of that column.
 

Greetings,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
stauder
Top achievements
Rank 1
answered on 09 Feb 2011, 12:22 PM
I've checked again all the samples provided with the silverlight components and did not find any sample application using AggregateFunction on a GridViewExpressionColumn.
There's an example of generic AggregateFunction but it uses the SourceField that  doesn't exist  for a GridViewExpressionColumn. And I can't see any way to access the values of the GridViewExpressionColumn. Can't you provide sample code that show how to calculate the sum of the "Total value in stock" of the "Calculated column" (RadGridView) example ?

Thanks in advance.
0
Maya
Telerik team
answered on 09 Feb 2011, 02:55 PM
Hi stauder,

May you take another look on the last sample project I attached in this thread ? Correct me if I am wrong, but the following lines define an aggregate function on a GridViewExpressionColumn and that function returns the sum of the values in that column:

Expression<Func<Player, int>> expression = p => p.Number - p.Number1;
var column = this.playersGrid.Columns["MyExpressionColumn"] as GridViewExpressionColumn;
column.Expression = expression;
 
var aggregate = new AggregateFunction<Player, int>
{
     AggregationExpression = players => players.Sum(p => p.Number - p.Number1),
     Caption = "Sum:"
};
column.AggregateFunctions.Add(aggregate);

Let me know in case there is some misunderstanding. 


Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
stauder
Top achievements
Rank 1
answered on 09 Feb 2011, 04:24 PM
Thanks so much, I did not understand that this piece of code was belonging to the GridViewExpressionColumn.

Just one thing remaining, if I modify a record in my ViewModel the grid is updated accordingly, but not the result of the AggregateFunction. How can I force the update without making a whole update ?

Thanks again.
0
Maya
Telerik team
answered on 09 Feb 2011, 04:27 PM
Hi stauder,

A possible approach may be to call CalculateAggregates() method of the RadGridView.
 

Regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
stauder
Top achievements
Rank 1
Answers by
Maya
Telerik team
stauder
Top achievements
Rank 1
Share this question
or