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

[Solved] Problems related to Grouping/Aggregation in RadGridView

6 Answers 336 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sumit
Top achievements
Rank 1
Sumit asked on 18 Sep 2010, 12:38 PM
Hi,

We are using RadGridView and we have added Aggregate functions.
We have 2 issues.

1. If we hide some column of the grid, in order to not display the related Footer values we clears the GroupDescriptor. Again if we show those hide columns, We perform grouping but this time the contents for GroupRow are not shown as Initially it was. (Find attached Images - Screen1 is the one with whole columns and the Group Rows/footers. Screen2 is the resultant after Regroup-Rebind the Grid)

2. Also we have aggregate function for Days of a month(Find Attached screen1) Now if I changed the grouping value the marked Content are also removed(See attached Screen2).  

Please look into this and suggest.

Thanks

Sumit Agrawal

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Sep 2010, 11:54 AM
Hi Sumit,

On performing the grouping you need to add the AggregateFunction of a particular column to the collection of AggregateFuntions of the GroupDescriptor. I am sending you a sample project illustrating the proposed solution. 
As for the second problem, I was not able to reproduce it. Thus in order to provide you with an appropriate solution, I would need more details about your project and scenario. You may change the sample application attached here so that it corresponds to your requirements and send it back to me.
 

Greetings,
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
Sumit
Top achievements
Rank 1
answered on 21 Sep 2010, 03:40 PM

Okay. I have tried to do by the same way which you have implemented and now I identify where the problem is.

I have 2 aggregate functions added to the columns in XAML.cs. They are working just fine for me while perform

grouping (while changing the grouping option).

I have added Custom Aggreegation function at runtime for 31 columns (find the code snippet below). So first

time it display the Result at the each grouped entry (at the bottom of each row footer column as well find FIRSTTIMERUN.png) but while I

change the grouping option, the grid footer is populated with Result but there is no Result for each Row footer

and this is happening for only those columns for which aggregate function is used at runtime. Please find attached

screens(FirstTimeRun.png & AfterGrouping.png) with more details. FirstTimeRun.png is for first time result and AfterGrouping.png is after change the grouping option. Please

look into this and suggest.

private IEnumerable<GridViewColumn> CreateDayColumns()
        {
             var temp = new List<GridViewColumn>();

            foreach (var gridColumn in from column in ((IDayColumnsViewModel)this.ViewModel).DayColumns
                                       select new RadNumericUpDownColumn()
                                       {
                                           IsVisible = column.IsVisible,
                                           Header = column.Header,
                                           DataMemberBinding = new Binding(column.BoundPropertyName),
                                           IsFilterable = false,
                                           IsGroupable = true,
                                           UniqueName = column.UniqueName,
                                           CellTemplateSelector = new DayCellDataTemplateSelector

(column.BoundPropertyName)
                                       })
            {
                SumFunction sumFunction = new SumFunction();
                sumFunction.SourceField = gridColumn.UniqueName;
                sumFunction.ResultFormatString = "{0:f2}";
                gridColumn.AggregateFunctions.Add(sumFunction);
                this.GridView.Columns.Add(gridColumn);
              
                temp.Add(gridColumn);
            }

            return temp;
        }

 

Thanks,

Sumit

0
Maya
Telerik team
answered on 24 Sep 2010, 02:32 PM
Hi Sumit,

In order to provide you with any further solution, I would need more details about the way you are implementing the functionality of changing the grouped-by element. Any other relevant information and code-snippet would be helpful.
 

Sincerely yours,
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
Sumit
Top achievements
Rank 1
answered on 25 Sep 2010, 08:18 AM
Hello Maya,

Below you can see the code used for binding and implementing the functionality of changing the grouped-by element.


        private void OnLoaded(object s, RoutedEventArgs e)
        {
            this.dayColumns = this.CreateDayColumns();
            this.CreateGroup(ClientFullNameLabel, ClientLabel);
          }  

 

private IEnumerable<GridViewColumn> CreateDayColumns()
        {
             var temp = new List<GridViewColumn>();

 

            foreach (var gridColumn in from column in ((IDayColumnsViewModel)this.ViewModel).DayColumns
                                       select new RadNumericUpDownColumn()
                                       {
                                           IsVisible = column.IsVisible,
                                           Header = column.Header,
                                           DataMemberBinding = new Binding(column.BoundPropertyName),
                                           IsFilterable = false,
                                           IsGroupable = true,
                                           UniqueName = column.UniqueName,
                                           CellTemplateSelector = new DayCellDataTemplateSelector(column.BoundPropertyName)
                                       })
            {
                SumFunction sumFunction = new SumFunction();
                sumFunction.SourceField = gridColumn.UniqueName;
                sumFunction.ResultFormatString = "{0:f2}";
                gridColumn.AggregateFunctions.Add(sumFunction);
                this.grdView.Columns.Add(gridColumn);
                temp.Add(gridColumn);
            }

            return temp;
        }   

 private void GroupByComboSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
        {
            // Combo selection occured before the grid was ready
            if (this.grdView == null) return;

            var item = (RadComboBoxItem)e.AddedItems[0];
            var member = string.Empty;
            var displayContent = string.Empty;

            switch (item.Content.ToString())
            {
                case ClientLabel:
                    member = ClientFullNameLabel;
                    displayContent = ClientLabel;
                    break;
                case FundIdentifierLabel:
                    member = FundIdentifierUuidLabel;
                    displayContent = FundIdentifierLabel;
                    break;
                case ServiceLabel:
                    member = ServiceUuidLabel;
                    displayContent = ServiceLabel;
                    break;
            }

            if (member == string.Empty)
            {
                //Remove grouping
                this.grdView.GroupDescriptors.Clear();
            }
            else
            {
                // Adds grouping to the grid
                this.CreateGroup(member, displayContent);
            }
        }

        private void CreateGroup(string member, string displayContent)
        {
            this.grdView.GroupDescriptors.Clear();

            var descriptor = new Telerik.Windows.Data.GroupDescriptor();
            descriptor.Member = member;
            descriptor.SortDirection = ListSortDirection.Ascending;
            descriptor.DisplayContent = displayContent;

           
            AggregateFunction func = new SumFunction { SourceField = "TotalUnits", ResultFormatString = "Total units: {0:f}" };
            descriptor.AggregateFunctions.Add(func);
            var column = this.grdView.Columns["TotalUnits"];
            column.AggregateFunctions.Clear();
            column.AggregateFunctions.Add(func);

            func = new CountFunction { ResultFormatString = "Total clients: {0}" };
            descriptor.AggregateFunctions.Add(func);
            column = this.grdView.Columns["ClientFullName"];
            column.AggregateFunctions.Clear();
            column.AggregateFunctions.Add(func);

            this.grdView.GroupDescriptors.Add(descriptor);
        }

 

                <r:RadGridView.Columns>
                    <r:GridViewDataColumn Header="Client" DataMemberBinding="{Binding Path=ClientFullName}" UniqueName="ClientFullName" IsReadOnly="True" >
                        <r:GridViewDataColumn.AggregateFunctions>
                            <telerik:CountFunction ResultFormatString="{}Total clients: {0}" />
                        </r:GridViewDataColumn.AggregateFunctions>
                    </r:GridViewDataColumn>
                   
                    <local:RadNumericUpDownColumn Header="Total Units" DataMemberBinding="{Binding Path=TotalUnitsUi, Mode=TwoWay}"   CellTemplateSelector="{StaticResource itemModifiedSelector}" UniqueName="TotalUnits" IsFilterable="False">
                        <local:RadNumericUpDownColumn.AggregateFunctions>
                            <telerik:SumFunction SourceField="TotalUnits" ResultFormatString="{}Total units: {0:f}" />
                        </local:RadNumericUpDownColumn.AggregateFunctions>
                    </local:RadNumericUpDownColumn>
                </r:RadGridView.Columns>

Thanks,
Sumit

0
Maya
Telerik team
answered on 27 Sep 2010, 08:59 AM
Hello Sumit,

As far as I can see from the code-snippet you provided, you add AggregateFunction-s only to the first two columns during the GreateGroup() method. However, if you want all the functions to appear after changing the Group, you need to define all the aggregates for every column. 
  

Best wishes,
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
Sumit
Top achievements
Rank 1
answered on 01 Oct 2010, 10:38 AM
Thanks Maya. I have added Aggregate functions for all columns in CreateGroup method and now its working.
Tags
GridView
Asked by
Sumit
Top achievements
Rank 1
Answers by
Maya
Telerik team
Sumit
Top achievements
Rank 1
Share this question
or