Conditional AggregateFunctions

9 posts, 1 answers
  1. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 02 Jul 2010 Link to this post

    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)
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 07 Jul 2010 Link to this post

    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
  3. DevCraft banner
  4. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 07 Jul 2010 Link to this post

    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 :
  5. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 12 Jul 2010 Link to this post

    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
  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 19 Jul 2010 Link to this post

    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
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 19 Jul 2010 Link to this post

    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
  8. Juliana
    Juliana avatar
    71 posts
    Member since:
    Feb 2008

    Posted 14 Feb 2011 Link to this post

    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
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Feb 2011 Link to this post

    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
  10. Juliana
    Juliana avatar
    71 posts
    Member since:
    Feb 2008

    Posted 17 Feb 2011 Link to this post

    Hi Vlad,

    Can you provide a sample?

    Thanks,
    Juliana
Back to Top
DevCraft banner