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

[Solved] How to manually calculate aggregate fields in a grouped grid

3 Answers 219 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 14 Jul 2009, 10:59 PM
Hi

Please can you tell me the best/easiest way to  manually calculate aggregate fields in a grouped grid. I need to be able to reset the variable storing my running total when the grid group has changed. I don't know what is the easiest way to detect if a group has changed. Also the code i use should not crash if the grid is not grouped because the code will be present inside a function which will be called by grids that may or may not be grouped

This was the best i could think of

dim groupIndex as integer = 0 
dim runningTotal as integer = 0 
 
In item data bound event  
 
if e.item.OwnerTableView.groupExpressions = 0  'no grouping  
   runningTotalrunningTotal = runningTotal + column value  
else 'grid is grouped  
   if grid.groupIndex = groupIndex then 'same group as last time  
         runningTotalrunningTotal = runningTotal + column value  
    else 'group changed  
        groupIndex = grid.groupIndex
         runningTotal =  column value  
end if  
 
 
thanks

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 17 Jul 2009, 02:07 PM
Hello andieje,

You can use programmatically built group expressions to display the results from the aggregate functions when you apply grouping for RadGrid as shown on this demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/expressions/defaultcs.aspx (see the implementation for details)

Thus the values will be updated accordingly when the state of the groups/group levels are changed. There is also an option to combine this approach with custom calculations intercepting the ItemDataBound event of the grid as explained here.

Greetings,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
andieje
Top achievements
Rank 1
answered on 20 Jul 2009, 11:08 PM
Hello

I should have pointed out that the grouping aggregate functions provided by the grid are of no use to me because the field I am performing the aggregate on is of type TimeSpan.

So i need to calculate manually grouped aggregate totals for a field of type TimeSpan which means i cannot use the built in aggregate group functions
0
Peter
Top achievements
Rank 1
answered on 23 Jul 2009, 03:15 PM
Hi,

You can use the approach suggested in this article, or just set "Custom" aggregate which will fire the OnCustomAggregate. I believe with one of those two approaches you will be able to achieve your goal.

Regards,
Petar
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
andieje
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Share this question
or