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

Multiple Groups with Different Header Templates

4 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Francisco Amador
Top achievements
Rank 1
Francisco Amador asked on 25 May 2010, 08:56 PM
In my grid I am attempting to group by a certain column, but display a different value in the group header. For this I found a solution in the forum that uses an IValueConverter. Unfortunately, in my grid I will have to group by two different columns like this at the same time. The grouping will occur programmatically. Is there a way to let the value converter know what the name of the column being grouped on is?

I haven't been able to come up with a way on my own, but I'm assuming it would come in through the ConverterParameter somehow. I just don't know how. The grid row object contains the description that I want to display so if there is a way to pass this information into the converter that would be the least expensive way of displaying it. Any ideas on this?

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 May 2010, 07:07 AM
Hi,

Why not use GroupHeaderTemplate property of the columns similar to this demo?

Best wishes,
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
Francisco Amador
Top achievements
Rank 1
answered on 26 May 2010, 03:19 PM
Thank you for pointing me in that direction, I had not seen that example before. I have not worked with aggregate functions before so I didn't know that you could use them for my purpose. That will work for what I need, however I'm still working out how to use the FirstFunction to display the value I need. When I have the FirstFunction aggregate declared in the GridViewDataColumn that I wish to display, it just shows the namespace name of the class of the row item ("BNS.DataObjects.CatalogItem"). How can I get it to display the value of a specific property from that first item?
0
Francisco Amador
Top achievements
Rank 1
answered on 26 May 2010, 03:43 PM
Actually, after trying it out with both of the columns that I need to do this for, Aggregate functions will not work since they will appear in all the group rows. The current code that I'm playing around with is:
<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding RegionCode}" Header="Category" IsVisible="False"
    <telerikGridView:GridViewDataColumn.GroupHeaderTemplate> 
        <DataTemplate> 
            <TextBlock Text="{Binding Group.Items[0].RegionDesc}" /> 
        </DataTemplate> 
    </telerikGridView:GridViewDataColumn.GroupHeaderTemplate> 
</telerikGridView:GridViewDataColumn> 

I know that the "Binding Group.Items[0].RegionDesc" will not work, but is there a way to grab the value of RegionDesc from the RegionCode GroupHeaderTemplate?
0
Francisco Amador
Top achievements
Rank 1
answered on 26 May 2010, 04:58 PM
Sorry, I went on a tangent on my last two posts without taking a closer look at what I had from my original question. I put an IValueConverter for each of the columns that I need like this:

<converters:CategoryCodeConverter x:Key="CategoryCodeConverter"/> 
    <converters:RegionCodeConverter x:Key="RegionCodeConverter"/> 
     
    <DataTemplate x:Key="GroupHeaderCategoryCodeTemplate"
        <TextBlock Text="{Binding Group.Key, Converter = {StaticResource CategoryCodeConverter}}" /> 
    </DataTemplate> 
 

I then used the template as usual

<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding CategoryCode}" Header="Category" IsVisible="False" GroupHeaderTemplate="{StaticResource GroupHeaderCategoryCodeTemplate}" /> 

If someone using this post for help has never used an IValueConverter, here is the structure
public class SomethingConverter : IValueConverter 
        { 
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
            { 
                    return Something; 
            } 
 
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
            { 
                return Something; 
            } 
    } 

Thanks for your help
Francisco Amador
Tags
GridView
Asked by
Francisco Amador
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Francisco Amador
Top achievements
Rank 1
Share this question
or