AggregateFunction not working when defined in code-behind

14 posts, 0 answers
  1. Bob
    Bob avatar
    12 posts
    Member since:
    Aug 2010

    Posted 10 Jan 2012 Link to this post

    I have a GridView that I am generating columns for dynamically.  Each column is bound to a nullable integer, but for some reason when I try to use an AggregateFunction on any of the columns, nothing displays in the footer cells.  Here's what the code looks like:

    foreach (DateTime date in this.VisibleWeeks)
    {
        var source = String.Format("WeeklyEstimates[{0}].Hours", i);
     
        var dataBinding = new Binding(source);
        dataBinding.Mode = BindingMode.TwoWay;
        dataBinding.UpdateSourceTrigger = UpdateSourceTrigger.Default;

        GridViewDataColumn column = new GridViewDataColumn
        {
            UniqueName = date.ToString(),
            DataMemberBinding = dataBinding,
            Header = date.ToShortDateString(),
            IsFilterable = false,
            TextAlignment = TextAlignment.Center,
        };
     
        column.AggregateFunctions.Add(new SumFunction() { SourceField = source });
        ResourceEstimateGrid.Columns.Add(column);
     
        i++;
    }

    Any suggestions on what I'm doing wrong?  Thanks.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Jan 2012 Link to this post

    Hi Bob,

    Actually, I can see nothing that may be causing the issue you described. Is the column filled properly with values ? Do you get any exceptions ? Is this behavior for all columns or only for those numeric ones ?  What is the structure of you business object - do you have all the properties exposed that are used for calculating the aggregates? 
    Generally, any further relevant information or code-snippet would be helpful in resolving the case. 


    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Bob
    Bob avatar
    12 posts
    Member since:
    Aug 2010

    Posted 11 Jan 2012 Link to this post

    Hi Maya,

    When I define the column in the Xaml, the SumFunction works as intended. 

    <telerik:GridViewDataColumn Header="Today"
                                DataMemberBinding="{Binding WeeklyEstimates[0].Hours}"
                                IsFilterable="False">
        <telerik:GridViewDataColumn.AggregateFunctions>
            <telerik:SumFunction />
        </telerik:GridViewDataColumn.AggregateFunctions>                   
    </telerik:GridViewDataColumn>

    However, if I define another column with the exact same Binding in the code-behind, the SumFunction doesn't do anything.

    private void AddColumns()
    {
        DateTime[] visibleWeeks = new[]{
            DateTime.Today,
            DateTime.Today.AddDays(7)
        };
     
        int index = 0;
        foreach (DateTime date in visibleWeeks)
        {
            String source = String.Format("WeeklyEstimates[{0}].Hours", index);
     
            Binding binding = new Binding(source);
            binding.Mode = BindingMode.TwoWay;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
     
            GridViewDataColumn column = new GridViewDataColumn()
            {
                UniqueName = date.ToString(),
                DataMemberBinding = binding,
                Header = date.ToShortDateString(),
                IsFilterable = false,
            };
     
            column.AggregateFunctions.Add(new SumFunction() { SourceField = source });
     
            ResourceEstimateGrid.Columns.Add(column);
            index++;
        }
    }

    As you can see in the screen shot, my "Today" column is summed up at the bottom, but my 2 dynamic columns are not.

    Thanks for your help.

    - Bob
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 13 Jan 2012 Link to this post

    Hi Bob,

    I finally managed to reproduce the issue and we are currently researching the cause of it. I will let you know as soon as we have more information about it.

    Thank you for you patience and cooperation.

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Mohd
    Mohd avatar
    19 posts
    Member since:
    Aug 2011

    Posted 16 Jan 2012 Link to this post

    I am waiting for a reply from a long time


    http://www.telerik.com/community/forums/silverlight/gridview/radgrid-export-to-excel-unable-to-maintain-decimal-format-for-number-less-than-4-digits.aspx
  6. Bob
    Bob avatar
    12 posts
    Member since:
    Aug 2010

    Posted 16 Jan 2012 Link to this post

    Maya,

    Any word on this issue?
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Jan 2012 Link to this post

    Hello Bob,

    We are still investigating the issues as changing the default behavior (as it is right now) might lead to some performance degradation which is definitely an undesired result. Generally, our concern is that recalculating the aggregates on inserting a new column may require a heavy calculating operation, which on the other side will need all the data from the data base. 
    Would it be possible for your exact scenario and settings to call CalculateAggregates() method of the grid:

    private void AddColumns()
    {
        DateTime[] visibleWeeks = new[]{
            DateTime.Today,
            DateTime.Today.AddDays(7)
        };
      
        int index = 0;
        foreach (DateTime date in visibleWeeks)
        {
            String source = String.Format("WeeklyEstimates[{0}].Hours", index);
      
            Binding binding = new Binding(source);
            binding.Mode = BindingMode.TwoWay;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
      
            GridViewDataColumn column = new GridViewDataColumn()
            {
                UniqueName = date.ToString(),
                DataMemberBinding = binding,
                Header = date.ToShortDateString(),
                IsFilterable = false,
            };
      
            column.AggregateFunctions.Add(new SumFunction() { SourceField = source });
      
            ResourceEstimateGrid.Columns.Add(column);
            index++;
        }
           ResourceEstimateGrid.CalculateAggregates();
    }

    Will that approach result in the desired behavior ? 

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Bob
    Bob avatar
    12 posts
    Member since:
    Aug 2010

    Posted 17 Jan 2012 Link to this post

    Maya,

    I added the call to CalculateAggregates() after the foreach loop as you suggested, but the totals are still not showing up.  This would be acceptable in my scenario if it worked, as this data calculation isn't too intensive, but unfortunately it doesn't seem to resolve the issue.

    Thanks,
    Bob
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 17 Jan 2012 Link to this post

    Hi Bob,

    Would you take a look at the sample attached and let me know whether it corresponds to your scenario ? Can you reproduce the same behavior on it ?
     

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Bob
    Bob avatar
    12 posts
    Member since:
    Aug 2010

    Posted 16 Feb 2012 Link to this post

    Maya,

    Sorry it has taken me so long to respond, this project got pushed aside for a while.

    I was able to replicate the issue in the project you included by doing the following:

    • Setting ShowGroupFooters="True" on the RadGridView.
    • Added a GroupDescriptor on the Grid, and grouping by Name

    If you do that,  you'll see that the footer at the bottom of the page will still show the aggregate values, but the group footers will not.

    Please let me know if you need more information.

    Thanks,
    Bob
  11. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 Feb 2012 Link to this post

    Hello Bob,

    Actually, in this case it would be the expected behavior as the group aggregates are not recalculated. You will need to refresh the source:

    private void Button1_Click(object sender, RoutedEventArgs e)
            {
                Binding binding = new Binding("Name");
                binding.Mode = BindingMode.TwoWay;
                binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
     
                GridViewDataColumn column = new GridViewDataColumn()
                {
                    DataMemberBinding = binding,
                    IsFilterable = false
                };
     
                column.AggregateFunctions.Add(new CountFunction());
     
                this.clubsGrid.Columns.Add(column);
                this.clubsGrid.Columns[2].AggregateFunctions.Add(new SumFunction());
     
                this.clubsGrid.CalculateAggregates();
                this.clubsGrid.Rebind();
            }
      

    Greetings,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  12. Bob
    Bob avatar
    12 posts
    Member since:
    Aug 2010

    Posted 21 Feb 2012 Link to this post

    Hi Maya,

    I tried calling Rebind() as you mentioned, but it didn't seem to fix the issue.  The group aggregates are still showing as blank.

    Do you have any other suggestions?  Is there any way I can send you my current solution so you can reproduce the issue?

    Thanks,
    Bob
  13. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 24 Feb 2012 Link to this post

    Hi Bob,

    Indeed, you are quite correct - I have retested the case when a group descriptor is created in advance and an aggregate is added. We will research the issue and let you know once we have more information on the topic.
    Thank you for your patience. 

    All the best,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  14. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Feb 2012 Link to this post

    Hi Bob,

    We are still investigating the issue in attempt to find the most appropriate solution so that no breaking changes are introduces. In the meantime, I would recommend you to work with ColumnGroupDescriptor (not GroupDescriptor) and add/ replace the aggregates of a column.
    Let me know in case you need assistance with the implementation. 

    Kind regards,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top