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
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.
Maya
the Telerik team
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
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.
Maya
the Telerik team
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
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.
Maya
the Telerik team