editable row and dynamic aggregation function

4 posts, 0 answers
  1. Jerry
    Jerry avatar
    70 posts
    Member since:
    Jan 2011

    Posted 21 May 2012 Link to this post

    Hi there,


    Currently, I'm working on a grid, where use is allowed to change the value of the cell. I have an aggregation function for this column. Everything is fine as long as user doesn't change the value. The aggregate value doesn't seem to change upon user change cell value.

    How should I do this, so the aggregated value will get updated upon user change one of the cells' value? By the way, I use a custom aggregate function this case.

    xmal
    <controls:RadGridView x:Name="ProjectRiskAnswersGridView" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" VerticalContentAlignment="Stretch"
                     Grid.Row ="1"
                     ItemsSource="{Binding RiskAnswers, Mode=TwoWay}"
                     DataLoadMode="Asynchronous"
                     CanUserDeleteRows="False"
                     CanUserFreezeColumns="False"
                     CanUserReorderColumns="False"
                     CanUserResizeColumns="False"
                     RowIndicatorVisibility="Collapsed"
                     IsFilteringAllowed="False"
                     GridLinesVisibility="None"
                     ShowGroupPanel="False"
                     CanUserSortColumns="True"
                     AutoGenerateColumns="False"
                     ValidatesOnDataErrors="None"
                     ShowColumnFooters="true"
                     SelectionMode="Single"
                      
                          >
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn UniqueName="RiskAreaColumn" IsReadOnly="True" DataMemberBinding="{Binding RiskQuestion.RiskArea.RiskAreaText, Mode=TwoWay, ValidatesOnDataErrors=False}" Header="Area"  />
            <telerik:GridViewDataColumn UniqueName="RiskQuestionColumn" IsReadOnly="True" DataMemberBinding="{Binding RiskQuestion.QuestionText, Mode=TwoWay, ValidatesOnDataErrors=False}" Header="Question" Width="500" />
            <local:RatingColumn UniqueName="RiskRatingColumn" IsReadOnly="True" DataMemberBinding="{Binding Rating, Mode=TwoWay, ValidatesOnDataErrors=False}" CellTemplate="{StaticResource RatingTemplate}" Header="Rating"  Width="200" />
            <telerik:GridViewDataColumn UniqueName="RiskPointsColumn" IsReadOnly="False" DataMemberBinding="{Binding Point, Mode=TwoWay, ValidatesOnDataErrors=False}" Header="Points" >
                <telerik:GridViewDataColumn.AggregateFunctions>
                    <local:TotalPointsFunction Caption="Total: "/>
                </telerik:GridViewDataColumn.AggregateFunctions>
            </telerik:GridViewDataColumn>
        </telerik:RadGridView.Columns>
    </controls:RadGridView>

    xmal.cs
    public class TotalPointsFunction : EnumerableAggregateFunction
    {
        protected override string AggregateMethodName
        {
            get { return "TotalPoints"; }
        }
     
        protected override Type ExtensionMethodsType
        {
            get { return typeof(Functions); }
        }
    }
     
    public static partial class Functions
    {
        public static int? TotalPoints<TSource>(IEnumerable<object> source)
        {
            var totalPoints = source.OfType<RiskAnswer>().Aggregate<RiskAnswer, int?>(0, (current, riskAnswer) => current + riskAnswer.Point);
            return totalPoints;
        }
    }


    thank you


    regards
    Jerry
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 May 2012 Link to this post

    Hi Jerry,

     When a PropertyChanged is raised then the aggregate result should be updated. I have tested the described functionality on this online demo and the aggregate results were updated once I committed the editing.

    Please let me know what have you done differently.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Jerry
    Jerry avatar
    70 posts
    Member since:
    Jan 2011

    Posted 22 May 2012 Link to this post

    Hi Didie,


    Thank you for your reply.


    Well, I don't think the demo actually fit into my problem. Since the rows is not editable in the demo.

    I have attached a few screenshots. 1.png shows the loading screen, which is correct. But 2.png, shows that after I edited a few rows, the aggregated value didn't get updated.

    Um, is it possible that you give me a sample project for this?

    thank you for your time.


    regards
    Jerry
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 23 May 2012 Link to this post

    Hello Jerry,

    Indeed your point is right. I have attached the test project based on the demo I suggested. After you edit a value in the StadiumCapacity column, you will notice that the aggregate is updated once the edit has been committed.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top