Programmatically setting an aggreggatefunction on a footer

8 posts, 0 answers
  1. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 01 Sep 2009 Link to this post

    Hello,

    I'd like to create a footer on some of my columns that would display a sum function that would update each time I add a new row.

    But I need to do it completely programmatically.

    Here's what I've done so far :

    if (r.grille.Contains("Ecriture")) 
                                        { 
                                                                                  
                                            SumFunction countFunction = new SumFunction(); 
                                            countFunction.ResultFormatString = "{0:F}"
                                            countFunction.SourceField = r.lib_zone; 
                                            countFunction.Caption = "Total : "
                                             
                                         
                                            FormGrille.ShowColumnFooters = true
                                            col.Footer = countFunction ; 
                                        }  

    The column is a GridViewDataColumn of type decimal wich is also created in code.

    The result I have with this code is that in the columns, it displays in the footer the message "Telerik.Windows.Data.sumfunction"

    Anyone knows how that would work ?


  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Sep 2009 Link to this post

    Hi,

    You should add the result from the function in the footer not the function itself. You can add the function in AggregateFunctions column property.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 01 Sep 2009 Link to this post

    Ok, but what property of my countFunction corresponds to the result of the function exactly ?
  5. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 01 Sep 2009 Link to this post

    Bonus Question :

    How do I update my footer when I add a new row in my RadGridView that changes the result of the aggregateFunction ?
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 04 Sep 2009 Link to this post

    Hello,

    I've attached small example to illustrate you how to achieve this. As to the new records the grid will rebind itself and will recalculate aggregates automatically.

    All the best,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Inquisitor Jax
    Inquisitor Jax avatar
    26 posts
    Member since:
    Sep 2009

    Posted 08 Sep 2009 Link to this post

    Vlad,

    In your sample, I replaced the CountFunction() with new SumFunction(), but get a InvalidOperationException:
    "No method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied arguments."

    Is there something additional to be added when creating a SumFunction from code?
  8. Inquisitor Jax
    Inquisitor Jax avatar
    26 posts
    Member since:
    Sep 2009

    Posted 08 Sep 2009 Link to this post

    Also, could you expand the example by showing how to programmatically add group footers?

    EDIT: k - found answer to this one:
    Handle the Grid_Grouping event, and then add a function to the e.Descriptor

    ...something like:
            private void RadGridView1_Grouping(object sender, Telerik.Windows.Controls.GridView.GridView.GridViewGroupingEventArgs e) 
            { 
                //only add group footer if column = "Age", and it is being grouped (ie: group is added, not removed) 
                if (e.GroupDescriptor.Member == "Age" && e.Action == CollectionChangeAction.Add) 
                { 
                    e.GroupDescriptor.AggregateFunctions.Add(_countFunction); 
                } 
            } 

  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Sep 2009 Link to this post

    Hello,

    You need to set SourceField for SumFunction.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
DevCraft banner