I have a GridView that is setup for certain types of information. My requirements for the project have changed such that in certain cases I will essentially have a Group header. Each group header will need to include specific controls within it. My question is, is there a way I can define the template of a Grouping Header?
if not, how can I add a row in the GridView that represents the group header? Imagine that this group header should show totals of the items within the group.
Thank you,
13 Answers, 1 is accepted
Can you please specify what do you mean by "Group Header" is that the GroupPanel at the top of the grid ( where you drag a header to group ) or the header of each group where the expand/collapse button resides ?
In both cases there is a solution but I will need to know which one you need templated.
Regards,
Pavel Pavlov
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.
I'm referring to the header of each group. Thank you
The property you need to set is RadGridView.GroupHeaderTemplate
this is a data template , where you can put any user controls. The DataContext is a GroupViewModel which gives you access to any needed properties of the group ( including aggregate results) .
If you find much troubles implementing this please feel free to send me your project with the requirements about the contents and behavior of the group header and I will gladly make the modifications for you.
Sincerely yours,
Pavel Pavlov
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.
Thank you for pointing this out. However, I still do not understand how to use a GroupHeaderTemplate to customize my header. The only thing I am trying to do at the moment is display the group name, which is a string. Currently, my GroupHeaderTemplate is defined as the following:
<telerik:RadGridView.GroupHeaderTemplate>
<DataTemplate>
<Grid Background="White">
<TextBlock Text="{Binding}" />
</Grid>
</DataTemplate>
</telerik:RadGridView.GroupHeaderTemplate>
But this displays "Telerik.Windows.Controls.GridView.GroupViewModel" instead of the group name. My grouping is defined programmatically as follows:
GroupDescriptor myGrouping = new GroupDescriptor();
myGrouping.Member = "UserName";
myGridView.GroupDescriptors.Add(myGrouping);
How do I get the UserName as the text displayed instead of "Telerik.Windows.Controls.GridView.GroupViewModel"?
Thank you
Please try :
<TextBlock Text="{Binding Header}" />
it should do the work.
Best wishes,
Pavel Pavlov
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.
Since the data context of the Group is seet to GroupViewModel explicitely, I cannot refer to the Command defined in my parent DataContext for the grid which is set through ItemSource. It only have Header, GroupDescriptor and Column properties.
How can I change/override the data context of the groupheader to a custom one?
I tried using the RelativeSource binding with Path but it is not working.
Thanks
Anoop
You can use ElementName Binding to set the DataContext for this button:
...DataContext="{Binding DataContext, ElementName=RadGridView1}"...
Regards,
Vlad
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.
Hi vlad,
Thanks. It worked.
Now again a bigger issue, and because of that I had to change the whole approach. I don't know if there is a solution for this.
The HyperLinkButton which I have placed on the GroupHeader was for Renaming the GroupName. I have a GroupID which is there as part of the columns in the grid which uniquely identifies the Group. But now when then user clicks on this hyperlink, I do not have a mechanism to get the current clicked group header. The GridViewModel provides the Metadata which includes the GroupName also but I would need to have access to the Items which falls in the group. Similar to the SelectedItem property which I can bind two way in the ViewModel and get the current selected Item is there a possibility of having a new property 'SelectedGroup ' which will provide the Row Items inside that group. ? Or even the GroupViewModel having this ColumnValues Property which provides values of the Column propety .
Thanks
Anoop
You can access the group from GroupViewModel Group property. You can access also the groped column using Column property of the group model.
All the best,
Vlad
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.
Hi vlad,
Did you mean GroupName or Group? What I need is row level information. The Grouping Column for me is GroupName but I need the GroupID which is a different column in the grid.
When they click on the group header, i have to access the items inside that group and read one of the column values. Any row would be fine because it is same for all items in that group.
Thanks
Anoop
In this case you can use Group.Items. Group is property of GroupViewModel (DataContext of the group header).
All the best,
Vlad
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.
Hi,
I also have a similar issue.
In Custom Group Header Template.
I overriden the Data context of hyperlink button with Grids DataContext.
Now the Command in the hyperlink is working.
But i need the whole collection of group in command parameter.
I tried to pass GroupViewModel as command parameter using RelativeSource as TemplatedParent. it is not working.
Can u suggest a way to achieve this.
Thanks
Jebouy
The Group.Items was useful. And finally the issue is resolved. I have used a dummy textblock which stores the GroupViewModel context and values. My Hyperlink Button will have the grids itemsource as viewmodel. So now I use relativepath to bind the dummy textblocks elements (text, and tag properties) to get the required data for my command parameter in hyperlink)
It was a long effort, but happy to find out a way.
Thanks once again.
Anoop