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

RadGridView GroupFooter Aggregates Don't Update Until You Leave the Row

6 Answers 305 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 07 Mar 2012, 09:34 PM
There appears to be an issue with Aggregate Functions in GroupFooters not getting updated until you leave the row.  I read this post about it that said it should be fixed but I am still not seeing the issue fixed in version 2012.1.215.  

This is what I did.  I created a new project and added a RadGridView.  Added a couple of columns that are bound to my data.  So that when I open the application it looks like screenshot1.

I then drag column Chud2 up into the Group Panel so it looks like screenshot2.

I then edit any field in column 1 and tab to column 2 and the Total: Aggregate for column 1 does not get updated as shown in screenshot3.

If I hit my Enter key or click to another row then the Total: Aggregate for column 1 gets updated as shown in screenshot4.

I have tried hooking up to the Grid's CellEditEnded event as recommended in other posts and calling the CalculateAggregates() method there but that does not solve the problem either.

My .xaml code is as follows:

<Window x:Class="RadControlsWpfApp6.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                Title="MainWindow" Height="350" Width="525">
        <Grid>
        <telerik:RadGridView x:Name="radGridView"
                             AutoGenerateColumns="False"
                             ShowGroupFooters="True"
                             CellEditEnded="radGridView_CellEditEnded">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn x:Name="_colChud"
                                            UniqueName="Chud"
                                            DataMemberBinding="{Binding Chud}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="Total: " />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn x:Name="_colChud2"
                                            UniqueName="Chud2"
                                            DataMemberBinding="{Binding Chud2}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="Total: " />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>

And my code behind is as follows:

namespace RadControlsWpfApp6
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            radGridView.ItemsSource = Data.GetData();
        }
 
        private void radGridView_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)
        {
            radGridView.CalculateAggregates();
        }
    }
 
    public class Data
    {
        private double _chud;
        public double Chud
        {
            get { return _chud; }
            set { _chud = value; }
        }
 
        private double _chud2;
        public double Chud2
        {
            get { return _chud2; }
            set { _chud2 = value; }
        }
 
        public static ObservableCollection<Data> GetData()
        {
            ObservableCollection<Data> data = new ObservableCollection<Data>();
 
            Data d = new Data() { Chud = 1, Chud2 = 1 };
            data.Add(d);
 
            d = new Data() { Chud = 2, Chud2 = 1 };
            data.Add(d);
 
            d = new Data() { Chud = 3, Chud2 = 1 };
            data.Add(d);
 
            d = new Data() { Chud = 4, Chud2 = 1 };
            data.Add(d);
 
            return data;
        }
    }
}

Am I missing something that would make the Group Footers update their Aggregates when you tab out of a cell?

Thanks,
Chad

6 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 08 Mar 2012, 10:25 AM
Hi Chad,

CalculateAggregates() will calculate all column aggregates but not the group ones. This is the reason for not updating group footer aggregates in your case. 
Generally, the aggregates will be updated when the editing is committed. This happens on Enter key press. What you can do is to create your own custom keyboard command provider that performs specific logic on Tab key to behave as Enter key on CellEditEnded.
Please take a look at this article and this blog post for further reference.
 
All the best,
Yordanka
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
Chad
Top achievements
Rank 1
answered on 08 Mar 2012, 10:22 PM
Thanks Yordanka for your quick reply.  I was able to look at the articles you mentioned and create a custom keyboard command provider that works.

However, I would think that functionality like this should be built into a grid control.  I don't think you should have to create a custom keyboard provider to handle updating totals when leaving a field.  I don't even think you should have to hook to an event and call CalculateAggreagtes to calculate column aggregates.  I think that anytime you leave the edit state of a cell the column and group aggregates should handle themselves and recalculate.  If you think about the way something like Excel handles editing a cell it behaves in this way and most of our users are used to this behavior.  Is this functionality something you plan on implementing in a future release?

Thanks,
Chad
0
Yordanka
Telerik team
answered on 09 Mar 2012, 08:56 AM
Hello Chad,

I'll try to explain the whole idea about calculating aggregates and editing a single property (cell). The problem comes from the fact that RadGridView calculate aggregates (along with moving row to the right place according to sorting, grouping and filtering) only on collection change and does not recalculate them on every property changed due to some performance and memory optimizations. In order to fulfill this task RadGridView should add property changed handler to every single item and the case could be even worse if nested properties are used (e.g. Name.FirstName).

There are also some pitfalls in some client-server applications, RadGridView calculates aggregates on the server if LinqToSQL is used as ItemsSource - in that case the performance hit will be even bigger (if we calculate aggregates on every cell). In fact calculating aggregates in general is a grouping operation (you can imagine what will happen).

Keeping this in mind we've decided to provide an option to change the default editing behavior (as you can see with a few lines of code) only in custom scenarios. You should also be aware that if there is sorting, grouping or filtering applied - committing item on every cell could lead to an expected (but not desired) behavior - like moving editing row around (e.g. you have ascending sorting by a column and you are changing its value from AAA to ZZZ the row will be moved to the last position).

Let me know if there is something unclear.
 
All the best,
Yordanka
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
Chad
Top achievements
Rank 1
answered on 16 Mar 2012, 04:07 PM
OK.  Thanks.
0
Raymond
Top achievements
Rank 1
answered on 06 Jan 2014, 09:41 PM
Hi Yordanka,

I have a similar situation where the selected record is edited externally to the grid and when the user selects save the data is updated to the underlying record in an observable collection.  In this scenario the column footers are updated using CalculateAggregates() however there is no keyboard event and consequently the group footers are not updated.

I tried using BeginEdit() and CommitEdit() for the grid but this had no effect.  Do you have any other suggestions?  Would it be feasible to add a CalculateGroupAggregates() method to allow control of when the group aggregates are recalculated?

Regards,

Ray
0
Raymond
Top achievements
Rank 1
answered on 08 Jan 2014, 05:33 AM
For anyone interested the solution can be found here though I still think a CalculateGroupAggregates() method would be simpler.
Tags
GridView
Asked by
Chad
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Chad
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Share this question
or