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

AggregateFunctions not updated

12 Answers 268 Views
GridView
This is a migrated thread and some comments may be shown as answers.
LE DREAU Steeve
Top achievements
Rank 1
LE DREAU Steeve asked on 27 May 2010, 01:31 PM
Hi Telerik Team,

I'm facing a problem with sum aggregatefunctions. 

<telerikGridView:GridViewDataColumn DataFormatString="{}{0:c}" DataMemberBinding="{Binding Total}" IsReadOnly="True" Width="0.4*" TextAlignment="Right" > 
                    <telerikGridView:GridViewDataColumn.Header> 
                        <TextBlock ToolTipService.ToolTip="Total">Total</TextBlock> 
                    </telerikGridView:GridViewDataColumn.Header> 
                    <telerikGridView:GridViewDataColumn.AggregateFunctions> 
                        <telerikData:SumFunction ResultFormatString="{}{0:c}" SourceField="Total" x:Name="AGR_Total" /> 
                    </telerikGridView:GridViewDataColumn.AggregateFunctions> 
                </telerikGridView:GridViewDataColumn> 

My GridView is binded to an ObservableCollection of objects. For each object I have a sub total property.
So Each line presents a sub total cell and I would like to display the Total (sum of sub total fields).
It seems aggregate sum function is not updated when I change a sub total property out of the line itself (for example, I change it programmaticaly). If I edit the line and then quit the edit mode, the Total is refreshed. My sub total property has it's notifyproperty event raised so its value is displayed but it doesn't execute the recalculation of Total agregate function.
I can call the recalculate function manually but I would prefer that it is triggered by the notifyPropertychanged event of my objects collection bound to the gridview.

If you want to reproduce the problem : create a usercontrol with a radgridview and a button. Then create a collection of objects with a numeric property. Bind it to a datagridview with a sum aggregate function on the columns bound to the numeric property. Into the button clicked event, change the value of one of the objects contained in the collection and see it is not updated.

Could you please help me about this ?

Thanks
Steeve

12 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 28 May 2010, 12:11 PM
Hi LE DREAU Steeve,

You may try to use UpdateSourceTrigger property when defining the binding of the column. For example:

DataMemberBinding="{Binding Total, Mode=TwoWay, UpdateSourceTrigger=Default}"

I hope that helps.


Regards,
Maya
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 31 May 2010, 01:20 PM
Hi,

Thanks for your answer but unfortunately, it doesn't solve my problem. When I update my object, the line is updated in live but not the aggregate sum function.
0
Pavel Pavlov
Telerik team
answered on 31 May 2010, 01:48 PM
Hello LE DREAU Steeve,

Currently calling the  gridView.CalculateAggregates is the recommended way to update the totals, whenever changes in data were made in code behind rather than by UI.

Kind regards,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 31 May 2010, 01:51 PM
Quite annoying behavior, but I don't have the choice. Thanks for your answer.
Regards,

Steeve
0
Geoff Hardy
Top achievements
Rank 1
answered on 24 Jun 2010, 09:43 PM
I agree with Le Dreau Steeve - it would be much better if the aggregate functions automatically updated themselves when the rows are updated. Having to call CalculateAggregates on the grid view doesn't work very well when using MVVM.
0
Vlad
Telerik team
answered on 25 Jun 2010, 07:17 AM
Hi,

 Recalculating aggregates on every property change will lead to huge performance problems. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mo
Top achievements
Rank 1
answered on 02 Sep 2010, 02:59 PM
I do agree that checking each property change can lead to a degraded performance. However, a solution should be provided. Most WPF applications use the MVVM pattern and this would be a great issue for anyone using this product.

I ran into this issue developing a WPF application that utilized the MVVM pattern. I had to programmatically update the grid which is bound to an observable collection in my ViewModel. I banged my head against the wall for quite some time until I saw this thread. I had to create a workaround for it, thanks to Dependency Property and Data triggers.

Solution:
- I created a DP in my view of type bool and created a PropertyChangedCallback for handling changes made to the property. All this callback does is extract my grid from the dependency object parameter and call the CalculateAggregate method on the grid.
- In my ViewModel, I also created a property of type boolean.
- In my xaml, I have a Data Trigger as follows

<Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding MyViewModelProperty}"
                                      Value="True">
                    <Setter Property="MyDependencyProperty" Value="True" />
                </DataTrigger>
            </Style.Triggers>
</Style>

Then whenever I change the data on my grid through code in my viewmodel, I just set the boolean property to true which then triggers the data trigger which in turn sets the DP which causes the callback to fire and update the grid.



0
Veselin Vasilev
Telerik team
answered on 02 Sep 2010, 03:48 PM
Hi Mo,

Thank you for sharing your solution with the community. I am sure a lot of people will find it useful.

Would you like to create a sample project and submit it as a code library?
This way I would be able to honor your work with a good amount of Telerik Points.


Sincerely yours,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Shreya
Top achievements
Rank 1
answered on 18 Feb 2015, 11:30 AM
Hi MO,
I am facing same problem. Since I am very new to these things I am not undersatnding your solution . Can you please give me detailed way to resolve this issue. Highly appreciate your fast response.

Shreya
0
Dimitrina
Telerik team
answered on 18 Feb 2015, 11:55 AM
Hello,

As to this specific issue, you can check the topic in our online documentation on: Aggregates are not updated.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Shreya
Top achievements
Rank 1
answered on 18 Feb 2015, 12:20 PM
Hi Dimitrina,
thanks for prompt reply. 
I am following MVVM pattern. I have textbox in gridview which is bound to observable collection.

 this.ListOfSelectedOptions = new ObservableCollection<OptionDetails>();
                this.ListOfSelectedOptions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ListOfSelectedOptions_CollectionChanged);

My gridview is like this

 <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn Footer="Total" FooterTextAlignment="Center" Width="Auto" DataMemberBinding="{Binding Path=OptionDesc}" Header="Accessory Name" TextAlignment="Center" HeaderTextAlignment="Center" />
                                <telerik:GridViewDataColumn Width="Auto" Header="Purchase Price" TextAlignment="Center" HeaderTextAlignment="Center">
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Width="65" HorizontalAlignment="Left" Style="{StaticResource errorStyle}" PreviewKeyDown="NumericTextBox_PreviewKeyDown" Margin="3,1,0,0" Text="{Binding Path=PurchasePriceExtras, Mode=TwoWay,   UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.AggregateFunctions>
                                        <telerik:SumFunction SourceField="PurchasePriceExtras" ResultFormatString="{}{0:c}"/>
                                    </telerik:GridViewDataColumn.AggregateFunctions>
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewDataColumn Width="Auto" Header="WDV" TextAlignment="Center" HeaderTextAlignment="Center">
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Width="65" HorizontalAlignment="Left" Style="{StaticResource errorStyle}" PreviewKeyDown="NumericTextBox_PreviewKeyDown" Margin="3,1,0,0" Text="{Binding Path=WDVExtras, Mode=TwoWay,   UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.AggregateFunctions>
                                        <telerik:SumFunction SourceField="WDVExtras" ResultFormatString="{}{0:c}"/>
                                    </telerik:GridViewDataColumn.AggregateFunctions>
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewDataColumn Width="Auto" Header="Maintenance" TextAlignment="Center" HeaderTextAlignment="Center">
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Width="65" HorizontalAlignment="Left" Style="{StaticResource errorStyle}" PreviewKeyDown="NumericTextBox_PreviewKeyDown" Margin="3,1,0,0" Text="{Binding Path=MaintenanceExtras, Mode=TwoWay,   UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.AggregateFunctions>
                                        <telerik:SumFunction SourceField="MaintenanceExtras" ResultFormatString="{}{0:c}"/>
                                    </telerik:GridViewDataColumn.AggregateFunctions>
                                </telerik:GridViewDataColumn>
                                <telerik:GridViewDataColumn Width="Auto" DataMemberBinding="{Binding Path=Conversion, Converter={StaticResource string2Bool}, ConverterParameter='INVERSE'}" Header="Conversion" TextAlignment="Center" HeaderTextAlignment="Center" />
                                <telerik:GridViewDataColumn Width="Auto" DataMemberBinding="{Binding Path=OptionStatus}" Header="Status" TextAlignment="Center" HeaderTextAlignment="Center"/>
                                <telerik:GridViewColumn Header="Remove" >
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <telerik:RadButton IsBackgroundVisible="False" Grid.Column="7" Margin="10 2" MinWidth="30" ToolTipService.ToolTip="Remove"
  Command="{Binding Path=DataContext.RemoveFromListCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
  CommandParameter="{Binding}">
                                                <Grid Background="#01FFFFFF" MinWidth="24" HorizontalAlignment="Center" VerticalAlignment="Center">
                                                    <Path Data="M1,1.0920105 L10.875,10.873011 M10.905006,1 L9.9050312,2.0619726 L1.0460064,10.921" 
     Stroke="#FF333333" StrokeThickness="2" RenderTransformOrigin="0.5,0.5" Stretch="Fill" Width="12" Height="12" VerticalAlignment="Center"/>
                                                </Grid>
                                            </telerik:RadButton>
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                </telerik:GridViewColumn>
                            </telerik:RadGridView.Columns>

Please suggest me how to resolve this issue. This collection changed is not invoked on any input given to textboxes.
I have also tried calling gridview.CalculateAggregates() on Textbox previewkeydown event but its still not updating the footers.
Pleas Help I am banging my head :(







0
Dimitrina
Telerik team
answered on 18 Feb 2015, 03:19 PM
Hello,

Is it possible for you to isolate the issue you experience in a demo project and send it to us in a new support ticket? You can also take a look at this blog post for a reference on how to isolate an issue. 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
LE DREAU Steeve
Top achievements
Rank 1
Answers by
Maya
Telerik team
LE DREAU Steeve
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Geoff Hardy
Top achievements
Rank 1
Vlad
Telerik team
Mo
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Shreya
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or