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

Adding an AggregateFunction to a column at runtime does not show its result before resorting or grouping

2 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 18 Jul 2014, 10:23 AM
Hi support,

I am adding a AggregateFunction to a gridcolumn with the following code:

bool showFooter = false;
foreach (var col in radGridView.Columns)
{
    if (col.UniqueName == "dauer") // Column with double-values
    {
        col.AggregateFunctions.Add(new SumFunction() { ResultFormatString = strFormat, SourceField = col.UniqueName });
        showFooter = true;
    }
}
radGridView.ShowColumnFooters = showFooter;

Adding a footer should only happens if my table has a column of data-type double named "dauer" otherwise columnfooters should not been shown. After doing this the footer has correctly been show but the first time the sum of the column is displayed when I sort a column of the grid via clicking on a column header.

You can reproduce this behavior in your sample-program "persistence framework / gridview serialization" when you put these lines of code in function "OnLoad" of Example.xaml.cs after calling this.EnsureLoadState() (of course you have to add a new column "dauer" to your dataset)

What do I have to do to show the results of the aggregate-function directly.

Thanks in advance

Marcus

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 18 Jul 2014, 02:49 PM
Hi Marcus,

RadGridView will update the information on the aggregates added at runtime once a CollectionChanged notification is raised from the bound source collection.

One way to do so is to apply any data operation - sorting, grouping or filtering. Another way would be to invoke RadGridView.CalculateAggregates() or RadGridView.Rebind() after you add the aggregate function.
For example:
...
radGridView.ShowColumnFooters = showFooter;
radGridView.CalculateAggregates();

How does this work for you?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Marcus
Top achievements
Rank 1
answered on 18 Jul 2014, 03:00 PM
Hi Didie,

thanks, this works fine.

Marcus
Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Marcus
Top achievements
Rank 1
Share this question
or