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

Same Aggregate Function for Multiple Columns

0 Answers 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Juliana
Top achievements
Rank 1
Juliana asked on 28 Feb 2012, 09:50 AM
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

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Juliana
Top achievements
Rank 1
Share this question
or