Same Aggregate Function for Multiple Columns

1 posts, 0 answers
  1. Juliana
    Juliana avatar
    71 posts
    Member since:
    Feb 2008

    Posted 28 Feb 2012 Link to this post

    Hi,

    My problem is when I use same function for two different columns I get double aggregate result for each of the column with the value for the last column (see the attached file). The code is

     <telerik:GridViewComboBoxColumn Header="Room Reserved" DataMemberBinding="{Binding RoomTypeId}"
                                                    ItemsSource="{Binding RoomTypeList, Source={StaticResource detailsViewModel}}"
                                                    DisplayMemberPath="Value" SelectedValueMemberPath="Id"
                                                    CellStyleSelector="{StaticResource styleSelector}"
                                                    >
                        <telerik:GridViewComboBoxColumn.AggregateFunctions>
                            <localTools:LodgingQuickSumFunction SourceField="RoomTypeId" FunctionName="GetUnassignedCount" Caption="Unassigned "/>
                        </telerik:GridViewComboBoxColumn.AggregateFunctions>
                    </telerik:GridViewComboBoxColumn>
                    
                    <telerikGrid:GridViewDataColumn Header="Room" DataMemberBinding="{Binding AccommodationRoomID}" Width="SizeToCells"
                                                    MinWidth="100"
                                                    IsFilterable="False"
                                                    CellTemplate="{StaticResource roomTemplate}"
                                                    CellEditTemplate="{StaticResource roomContentTemplate}"
                                                    >
                        <telerik:GridViewDataColumn.AggregateFunctions>
                            <localTools:LodgingQuickSumFunction SourceField="AccommodationRoomID" FunctionName="GetUnassignedCount" Caption="Unassigned "/>
                        </telerik:GridViewDataColumn.AggregateFunctions>
                    </telerikGrid:GridViewDataColumn>

    public class LodgingQuickSumFunction : EnumerableSelectorAggregateFunction
        {
            protected override string AggregateMethodName
            {
                get
                {
                    return this.FunctionName;
                }
            }

            protected override Type ExtensionMethodsType
            {
                get
                {
                    return typeof(LodgingQuickStatistics);
                }
            }
        }

        public static class LodgingQuickStatistics
        {
            public static int GetUnassignedCount<TSource>(IEnumerable<TSource> source, Func<TSource, int?> selector)
            {
                int itemCount = source.Count();
                if (itemCount > 0)
                {
                    int unassignedCount = (from i in source
                                 where selector(i) == null || selector(i) == DBDataHelper.UNDEFINED_ID
                                 select selector(i)).Count();
                    return unassignedCount;
                }

                return 0;
            }
        }

    What am I doing wrong?
    Juliana
Back to Top