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

GridView - Conditional CellTemplate

13 Answers 196 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frustrated Dev
Top achievements
Rank 1
Frustrated Dev asked on 20 Mar 2010, 07:26 PM
Hello,

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

Sort by
0
Pavel Pavlov
Telerik team
answered on 22 Mar 2010, 10:34 AM
Hello Frustrated Dev,

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.
0
Frustrated Dev
Top achievements
Rank 1
answered on 22 Mar 2010, 01:39 PM
Hello,

I'm referring to the header of each group. Thank you
0
Pavel Pavlov
Telerik team
answered on 22 Mar 2010, 01:51 PM
Hello Frustrated Dev,

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.
0
Frustrated Dev
Top achievements
Rank 1
answered on 22 Mar 2010, 04:05 PM
Hello,

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
0
Pavel Pavlov
Telerik team
answered on 22 Mar 2010, 04:15 PM
Hello Frustrated Dev,

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.
0
anoop c
Top achievements
Rank 1
answered on 07 Apr 2010, 04:35 PM
I was also having a similar requirement to show controls on the Group Header.  And using the GroupHeaderTemplate worked. Now I have a different problem. One of the control that I placed on the GroupRow is a HyperLinkButton. I need to attach a Command to this so that I can handle the Click. (I am using MVVM and not code behind). 

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
0
Vlad
Telerik team
answered on 08 Apr 2010, 06:18 AM
Hi,

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.
0
anoop c
Top achievements
Rank 1
answered on 09 Apr 2010, 08:51 AM

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

0
Vlad
Telerik team
answered on 14 Apr 2010, 01:10 PM
Hi,

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.
0
anoop c
Top achievements
Rank 1
answered on 14 Apr 2010, 02:18 PM

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
0
Vlad
Telerik team
answered on 14 Apr 2010, 02:28 PM
Hello,

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.
0
Jebouy
Top achievements
Rank 1
answered on 17 Apr 2010, 05:38 AM

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

0
anoop c
Top achievements
Rank 1
answered on 30 Apr 2010, 11:41 AM
VLad,

   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
Tags
GridView
Asked by
Frustrated Dev
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Frustrated Dev
Top achievements
Rank 1
anoop c
Top achievements
Rank 1
Vlad
Telerik team
Jebouy
Top achievements
Rank 1
Share this question
or