private void CreateGroup(string member, string displayContent) |
{ |
this.RosterRecordGrid.GroupDescriptors.Clear(); |
var descriptor = new Telerik.Windows.Data.GroupDescriptor(); |
descriptor.Member = member; |
descriptor.SortDirection = ListSortDirection.Ascending; |
descriptor.DisplayContent = displayContent; |
this.RosterRecordGrid.GroupDescriptors.Add(descriptor); |
} |
<pc:CustomDataGrid |
Grid.Row="3" |
x:Name="RosterRecordGrid" |
ItemsSource="{Binding Path=Entities}" |
AutoExpandGroups="True" |
AutoGenerateColumns="False" |
FrozenColumnCount="7" |
CanUserFreezeColumns="False" |
CanUserDeleteRows="False" |
CanUserInsertRows="False" |
CanUserReorderColumns="False" |
CanUserResizeColumns="False" |
CanUserSortColumns="False" |
ShowColumnFooters="True" |
ShowGroupFooters="True" |
ShowInsertRow="False" |
IsBusy="{Binding BusyIndicator.IsBusy}"> |
<r:RadGridView.Columns> |
<r:GridViewDataColumn Header="Client" DataMemberBinding="{Binding Path=ClientFullName}" > |
<r:GridViewDataColumn.AggregateFunctions> |
<telerik:CountFunction ResultFormatString="{}Total clients: {0}" /> |
</r:GridViewDataColumn.AggregateFunctions> |
</r:GridViewDataColumn> |
<r:GridViewDataColumn Header="Service" DataMemberBinding="{Binding Path=ServiceUuid, Converter={StaticResource lookupConverter}, ConverterParameter=Services}"> |
</r:GridViewDataColumn> |
<r:GridViewDataColumn Header="Fund Identifier" DataMemberBinding="{Binding Path=FundIdentifierUuid, Converter={StaticResource lookupConverter}, ConverterParameter=FundIdentifiers}"> |
</r:GridViewDataColumn> |
<r:GridViewDataColumn Header="Subservice" DataMemberBinding="{Binding Path=SubserviceUuid, Converter={StaticResource lookupConverter}, ConverterParameter=Subservices}"> |
</r:GridViewDataColumn> |
<r:GridViewDataColumn Header="Place of Service" DataMemberBinding="{Binding Path=PlaceOfServiceCode, Converter={StaticResource lookupConverter}, ConverterParameter=PlacesOfService}"> |
</r:GridViewDataColumn> |
<r:GridViewDataColumn Header="Unit Price" DataMemberBinding="{Binding Path=UnitPrice}"> |
</r:GridViewDataColumn> |
<r:GridViewDataColumn Header="Total Units" DataMemberBinding="{Binding Path=TotalUnits}" CellTemplateSelector="{StaticResource selector}"> |
<r:GridViewDataColumn.AggregateFunctions> |
<telerik:SumFunction SourceField="TotalUnits" ResultFormatString="{}Total units: {0}" /> |
</r:GridViewDataColumn.AggregateFunctions> |
</r:GridViewDataColumn> |
</r:RadGridView.Columns> |
</pc:CustomDataGrid> |
32 Answers, 1 is accepted
This is the expected behavior, as the column aggregates are shown only when grouping by the UI. In your project when adding a group descriptor programmatically at run time, you need also to define the column's functions in the code - in your case in the method CreateGroup. For example:
CountFunction f = new CountFunction();
( ( GridViewDataColumn )this.radGridView.Columns[ "ID" ] ).AggregateFunctions.Add( f );
Kind regards,
Maya
the Telerik team
private void CreateGroup(string member, string displayContent) |
{ |
this.RosterRecordGrid.GroupDescriptors.Clear(); |
var descriptor = new Telerik.Windows.Data.GroupDescriptor(); |
descriptor.Member = member; |
descriptor.SortDirection = ListSortDirection.Ascending; |
descriptor.DisplayContent = displayContent; |
this.RosterRecordGrid.GroupDescriptors.Add(descriptor); |
var column = this.RosterRecordGrid.Columns["TotalUnitsColumn"]; |
//column.AggregateFunctions.Clear(); |
var function = new SumFunction() { SourceField = "TotalUnits", ResultFormatString = "{}Total units: {0}" }; |
column.AggregateFunctions.Add(function); |
} |
You need to add your function to the AggregateFunctions of the GroupDescriptor
private void CreateGroup(string member, string displayContent)
{ ...
var descriptor = new Telerik.Windows.Data.GroupDescriptor();
var function = new SumFunction() { SourceField = "TotalUnits", ResultFormatString = "{}Total units: {0}" };
column.AggregateFunctions.Add(function);
descriptor.AggregateFunctions.Add(function);
}
Maya
the Telerik team
When we group by using the UI, we get the expected result. but not when grouping using the code CreateGroup().
Any suggestion/solution is highly appreciated.
Thanks,
Karthik
Please paste me your code , and I will make the modifications necessary .
Sincerely yours,
Pavel Pavlov
the Telerik team
public void ChangeGroup() |
{ |
// Do not show the grouped column in the view |
RadGridView1.Columns[0].IsVisible = false; |
RadGridView1.GroupDescriptors.Clear(); |
var descriptor = new Telerik.Windows.Data.GroupDescriptor(); |
descriptor.Member = "field1"; |
descriptor.DisplayContent = "field1"; |
this.Dispatcher.BeginInvoke(new Action(() => this.RadGridView1.GroupDescriptors.Add(descriptor))); |
var column = this.RadGridView1.Columns[2]; |
var function = new SumFunction() { SourceField = "field3", ResultFormatString = "{}{0}" }; |
column.AggregateFunctions.Add(function); |
descriptor.AggregateFunctions.Add(function); |
} |
<telGrid:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" CanUserResizeColumns="False" |
CanUserReorderColumns="True" AutoExpandGroups="True" RowDetailsVisibilityMode="VisibleWhenSelected" |
ShowGroupPanel="True" IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed" CanUserFreezeColumns="False" AreRowDetailsFrozen="False" |
ShowGroupFooters="True" |
Background="White" VerticalAlignment="Top" Margin="0 10 0 0" Grid.ColumnSpan="2"> |
<telGrid:RadGridView.Columns> |
<telGrid:GridViewDataColumn DataMemberBinding="{Binding field1}" Header="field1" IsReadOnly="True" Width="285" IsVisible="False"> |
</telGrid:GridViewDataColumn> |
<telGrid:GridViewDataColumn DataMemberBinding="{Binding field2}" Header="field2" IsReadOnly="True" Width="285"></telGrid:GridViewDataColumn> |
<telGrid:GridViewDataColumn DataMemberBinding="{Binding field3}" Header="field3" IsReadOnly="True" Width="135"> |
<telGrid:GridViewDataColumn.AggregateFunctions> |
<telData:SumFunction SourceField="field3" /> |
</telGrid:GridViewDataColumn.AggregateFunctions> |
</telGrid:GridViewDataColumn> |
<telGrid:GridViewDataColumn DataMemberBinding="{Binding field4}" Header="field4" IsReadOnly="True" Width="135"></telGrid:GridViewDataColumn> |
</telGrid:RadGridView.Columns> |
</telGrid:RadGridView> |
Thanks
Karthik
You need to change the definition of the property ResultFormatString. As you are setting it in the code-behind, the proper way of doing it is as follows:
var function = new SumFunction()
{ SourceField = "field3", ResultFormatString = "{0}" };
Greetings,
Maya
the Telerik team
- Karthik
I need to see the C2 format and I tried this but still the cell in the Group Footer is empty
I tried many things but this was my last attempt
void
rgvTest_AutoGeneratingColumn(
object
sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
if
(e.Column.UniqueName ==
"Property2"
)
e.Column.AggregateFunctions.Add(
new
SumFunction() { SourceField =
"Property2"
, ResultFormatString =
"{C2}"
});
}
Could you please try with the ResultFormatString set to "{0:C2}"?
Regards,
Yavor Georgiev
the Telerik team
Do you group by dragging the column header, or programmatically? Also, what version of our controls are you using?
Greetings,
Yavor Georgiev
the Telerik team
rgvTest.GroupDescriptors.Add(
new
Telerik.Windows.Data.GroupDescriptor() { DisplayContent =
"Test"
, Member =
"Property1"
});
void
MainPage_Loaded(
object
sender, RoutedEventArgs e)
{
Expression.Blend.SampleData.PrestiluxData.PrestiluxData p =
new
Expression.Blend.SampleData.PrestiluxData.PrestiluxData();
rgvTest.ItemsSource = p.Collection;
rgvTest.ShowGroupFooters =
true
;
rgvTest.AutoGenerateColumns =
true
;
rgvTest.AutoGeneratingColumn +=
new
EventHandler<GridViewAutoGeneratingColumnEventArgs>(rgvTest_AutoGeneratingColumn);
rgvTest.GroupDescriptors.Add(
new
Telerik.Windows.Data.GroupDescriptor() { DisplayContent =
"Test"
, Member =
"Property1"
});
rgvTest.AutoExpandGroups =
true
;
}
void
rgvTest_AutoGeneratingColumn(
object
sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
GridViewDataColumn column = e.Column
as
GridViewDataColumn;
if
(column.DataType ==
typeof
(
double
))
column.DataFormatString =
"{0:C2}"
;
if
(e.Column.UniqueName ==
"Property2"
)
{
var descriptor =
new
Telerik.Windows.Data.GroupDescriptor();
var function =
new
SumFunction() { SourceField = e.Column.UniqueName, ResultFormatString =
"{0}"
};
column.AggregateFunctions.Add(function);
descriptor.AggregateFunctions.Add(function);
}
}
Could you please try to use our ColumnGroupDescriptor instead? It should inherit all AggregateFunctions from its Column.
All the best,
Yavor Georgiev
the Telerik team
I'm unable to figure out where I find this ColumnGroupDescriptor
if
(e.Column.UniqueName ==
"Property2"
)
{
var descriptor =
new
Telerik.Windows.Controls.GridView.ColumnGroupDescriptor();
descriptor.Column = column;
var function =
new
SumFunction() { SourceField = e.Column.UniqueName, ResultFormatString =
"{0}"
};
column.AggregateFunctions.Add(function);
}
Greetings,
Yavor Georgiev
the Telerik team
I apologize for the confusion, you said you used the latest version of the controls a bit earlier in this thread. Could you please open a separate support ticket for this issue and attach your complete application?
Kind regards,
Yavor Georgiev
the Telerik team
Thank you for submitting your inquiry to the Telerik Support.
Your ticket ID is: 415354 (view all your support tickets)
It appears that this was an issue with initial grouping in our Q2 release. I suggest to use a newer release and use ColumnGroupDescriptor, as I advised you earlier.
Best wishes,
Yavor Georgiev
the Telerik team
I'm also experiencing the same behavior where my group footers are not rendering. If i manually group/ungroup it, the aggregates will come back.
I have updated my telerik to the newest version at this time: 2011.1.419.1040
I've also tried using the ColumnGroupDescriptors with no avail.
I add the GroupDescriptors during the initialization of my view (in the constructor).
CounterPartyExposureView.GroupDescriptors.Clear();
ColumnGroupDescriptor gd =
new
ColumnGroupDescriptor();
gd.Column = CounterPartyExposureView.Columns[4];
CounterPartyExposureView.GroupDescriptors.Add(gd);
I have also tried grouping in the xaml instead and played around with a few things.
Tony
Could you please check the attached sample project where the aggregates are shown correctly? Let me know in case I have missed something and the scenario for reproducing the problem is different.
Best wishes,
Yordanka
the Telerik team
The only other difference I can think of is that some of the fields are editable in the one that doesn't work, but I can't see why that would be a problem.
I've attached a screenshot.
PS. I'm using 2011.1.419.1040, Q2 doesn't seem to have changed this but does seem to have broken other grouping related stuff.
Could you isolate the problem in a sample project and send it to us (via support ticket) so we can check what is going wrong? Thank you in advance.
Regards,
Yordanka
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!