GridView - Conditional CellTemplate

14 posts, 0 answers
  1. Frustrated Dev
    Frustrated Dev avatar
    35 posts
    Member since:
    Oct 2006

    Posted 20 Mar 2010 Link to this post

    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,
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 22 Mar 2010 Link to this post

    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.
  3. DevCraft banner
  4. Frustrated Dev
    Frustrated Dev avatar
    35 posts
    Member since:
    Oct 2006

    Posted 22 Mar 2010 Link to this post

    Hello,

    I'm referring to the header of each group. Thank you
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 22 Mar 2010 Link to this post

    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.
  6. Frustrated Dev
    Frustrated Dev avatar
    35 posts
    Member since:
    Oct 2006

    Posted 22 Mar 2010 Link to this post

    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
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 22 Mar 2010 Link to this post

    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.
  8. anoop c
    anoop c avatar
    15 posts
    Member since:
    Jul 2009

    Posted 07 Apr 2010 Link to this post

    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
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Apr 2010 Link to this post

    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.
  10. anoop c
    anoop c avatar
    15 posts
    Member since:
    Jul 2009

    Posted 09 Apr 2010 Link to this post

    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

  11. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Apr 2010 Link to this post

    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.
  12. anoop c
    anoop c avatar
    15 posts
    Member since:
    Jul 2009

    Posted 14 Apr 2010 Link to this post


    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
  13. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Apr 2010 Link to this post

    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.
  14. Jebouy
    Jebouy avatar
    8 posts
    Member since:
    Sep 2009

    Posted 17 Apr 2010 Link to this post

    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

  15. anoop c
    anoop c avatar
    15 posts
    Member since:
    Jul 2009

    Posted 30 Apr 2010 Link to this post

    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
Back to Top
DevCraft banner