AggregateFunctions not updated

13 posts, 0 answers
  1. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 27 May 2010 Link to this post

    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
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 May 2010 Link to this post

    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.
  3. DevCraft banner
  4. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 31 May 2010 Link to this post

    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.
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 31 May 2010 Link to this post

    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.
  6. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 31 May 2010 Link to this post

    Quite annoying behavior, but I don't have the choice. Thanks for your answer.
    Regards,

    Steeve
  7. Geoff Hardy
    Geoff Hardy avatar
    58 posts
    Member since:
    Feb 2010

    Posted 24 Jun 2010 Link to this post

    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.
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Jun 2010 Link to this post

    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
  9. Mo
    Mo avatar
    3 posts
    Member since:
    Jun 2010

    Posted 02 Sep 2010 Link to this post

    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.



  10. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 02 Sep 2010 Link to this post

    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
  11. Shreya
    Shreya avatar
    18 posts
    Member since:
    Aug 2014

    Posted 18 Feb 2015 in reply to Mo Link to this post

    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
  12. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Feb 2015 Link to this post

    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.

     
  13. Shreya
    Shreya avatar
    18 posts
    Member since:
    Aug 2014

    Posted 18 Feb 2015 in reply to Dimitrina Link to this post

    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 :(







  14. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Feb 2015 Link to this post

    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.

     
Back to Top
DevCraft banner