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

AggregateFunction not working when defined in code-behind

13 Answers 168 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bob
Top achievements
Rank 1
Bob asked on 10 Jan 2012, 06:11 PM
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.

13 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 11 Jan 2012, 08:37 AM
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 >>

0
Bob
Top achievements
Rank 1
answered on 11 Jan 2012, 06:20 PM
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
0
Maya
Telerik team
answered on 13 Jan 2012, 02:28 PM
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 >>

0
Mohd
Top achievements
Rank 1
answered on 16 Jan 2012, 06:39 AM
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
0
Bob
Top achievements
Rank 1
answered on 17 Jan 2012, 05:04 AM
Maya,

Any word on this issue?
0
Maya
Telerik team
answered on 17 Jan 2012, 07:33 AM
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 >>

0
Bob
Top achievements
Rank 1
answered on 17 Jan 2012, 04:59 PM
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
0
Maya
Telerik team
answered on 17 Jan 2012, 06:07 PM
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 >>

0
Bob
Top achievements
Rank 1
answered on 16 Feb 2012, 07:13 PM
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
0
Maya
Telerik team
answered on 21 Feb 2012, 05:25 PM
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 >>
0
Bob
Top achievements
Rank 1
answered on 21 Feb 2012, 10:17 PM
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
0
Maya
Telerik team
answered on 24 Feb 2012, 05:04 PM
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 >>
0
Maya
Telerik team
answered on 27 Feb 2012, 03:16 PM
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 >>
Tags
GridView
Asked by
Bob
Top achievements
Rank 1
Answers by
Maya
Telerik team
Bob
Top achievements
Rank 1
Mohd
Top achievements
Rank 1
Share this question
or