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

Conditional AggregateFunctions

8 Answers 198 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc Roussel
Top achievements
Rank 2
Marc Roussel asked on 02 Jul 2010, 07:26 PM
I have the code bellow :

 
GroupDescriptor GDDocNum = new GroupDescriptor() { DisplayContent = "DocNum", Member = "DocNum" };  
 
GDDocNum.AggregateFunctions.Add(new SumFunction() { Caption = "Total QtyMatPre. : ", SourceField = "QtyMatPre" });  
GDDocNum.AggregateFunctions.Add(new SumFunction() { Caption = "Total QtyTubes. : ", SourceField = "QtyTubes" });  
 

How can I have the same thing but based on another column,
Let say I have a column that have 'P' or 'Q'.  I would like to sum the 'P' and sum de 'Q'

To obtain something like this on the Group line

(Total QtyMatPre for P = 1234),  (Total QtyTubes for P = 988) - (Total QtyTubes for Q = 988)

8 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 07 Jul 2010, 10:08 AM
Hi Marc Roussel,

I have prepared a small sample for you . It utilizes a custom aggregate function which will sum all items with type 'P'.
The same way you may add another custom aggregate function to sum all "Q"s.

Let me know if you need further assistance.

Best wishes,
Pavel Pavlov
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
Marc Roussel
Top achievements
Rank 2
answered on 07 Jul 2010, 12:35 PM
Hi,

Thank you for the sample but this isn't exactly what I need.
I group on DocNum and I need the Aggregates to be on THIS group only.  Not doing 2 groups or having 2 Group line as I saw when I did group the Type column of your sample.

If you read my first message,  having it this way :

(Total QtyMatPre for P = 1234),  (Total QtyTubes for P = 988) - (Total QtyTubes for Q = 988)

On a single group line when groupping the DocNum.
As you can see in the code example I given, you remark I have 2 aggregates on 2 fields

So I need the same thing as this which mean having my Group Line showing the same information but SUMING the 2 fields for the 'P's and for the 'Q's I can't have 2 group line greay one for the P and one for the Q, it needs to be on the same line which is the group of DocNum

Here's another way to explaining.

If I group DocNum, which isn't the column that have P or Q, I have many children per group in the grid,
In these children, I have the column P or Q, so on the Group line, I need to see this :

(Total QtyMatPre for P = 1234),  (Total QtyTubes for P = 988) - (Total QtyTubes for Q = 988)

As you can see this is only one group line that are the sums of every single child element of the DocNum Group

Here's a simulated screenshot of what it should look like :
0
Accepted
Pavel Pavlov
Telerik team
answered on 12 Jul 2010, 02:29 PM
Hello Marc Roussel,

I believe with the sample attached  we are getting closer to the final goal.

Best wishes,
Pavel Pavlov
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
Marc Roussel
Top achievements
Rank 2
answered on 19 Jul 2010, 12:27 PM
Hi,

Well, it seems you're close enough to say that it's exactly that.

Just to know, do you plan to make it easier in a near future or I really have to copy paste this class
and learn from it as it will be like that forever ?

Thank you
0
Pavel Pavlov
Telerik team
answered on 19 Jul 2010, 01:01 PM
Hi Marc,

We are always open to suggestions. In case you think there is a way to provide a better API we will be glad  to consider your ideas when planning our next wave of improvements to aggregation logic  in RadGridView. Though we are trying to keep things consistent and avoid breaking changes, if we see a chance to improve anything in RadGridView to bring more benefit to our customers we will do it .

Regards,
Pavel Pavlov
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
Juliana
Top achievements
Rank 1
answered on 14 Feb 2011, 01:03 PM
Hello Pavel,

I have columns with checkboxes in datatemplate. I need to count how many of them are checked. I decided to use custom EnumerableAggregateFunction. But the thing is that I have about 50 such columns. So I don't want just to multiply pretty the same classes. Is there any way to pass to AggregateMethod the column as sender or some of column parameters like datamemberbinding or uniquename? Something like that
public static double MyAggregateMethod<TSource>(IEnumerable<Item> source, object sender)
or
public static double MyAggregateMethod<TSource>(IEnumerable<Item> source, string columnUniqueName)

Best Regards,
Juliana
0
Vlad
Telerik team
answered on 17 Feb 2011, 02:14 PM
Hi,

 This will not be that easy since these methods are generic. You need to have some additional logic (a separate method) which will instantiate these methods with correct arguments. 

Kind regards,
Vlad
the Telerik team
0
Juliana
Top achievements
Rank 1
answered on 17 Feb 2011, 03:17 PM
Hi Vlad,

Can you provide a sample?

Thanks,
Juliana
Tags
GridView
Asked by
Marc Roussel
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Marc Roussel
Top achievements
Rank 2
Juliana
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or