I need to customize the group headings and just can't figure it out.
I've read the documentation for customizing GridGroupHeaderItem and I've tried to follow the sample provided but it just isn't working quite right.
The issue is that I have more than one column that needs additional information in the header, so using e.item.DataItem doesn't help after the initial grouping. So how do I find the header and row data for the secondary groupings?
The grid needs to be able to group on all the columns that need customizing, but it won't be grouped when it loads. Grouping will be done if/when user chooses. So I can't follow the exmple provided in documentation which sets up the grouping declaratively when the grid loads.
I've read the documentation for customizing GridGroupHeaderItem and I've tried to follow the sample provided but it just isn't working quite right.
The issue is that I have more than one column that needs additional information in the header, so using e.item.DataItem doesn't help after the initial grouping. So how do I find the header and row data for the secondary groupings?
The grid needs to be able to group on all the columns that need customizing, but it won't be grouped when it loads. Grouping will be done if/when user chooses. So I can't follow the exmple provided in documentation which sets up the grouping declaratively when the grid loads.
4 Answers, 1 is accepted
0
Hello Rayne,
You can use ItemDataBound event handler to modify the GroupHeaderText:
Alternatively, you can use Templates to achieve the requested functionality:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/headerandfootertemplates/defaultcs.aspx
Hope this helps. If you have different requirements or further instructions, please elaborate on your specific scenario and send us sample screenshots or video demonstrating the desired behavior.
Regards,
Eyup
Telerik
You can use ItemDataBound event handler to modify the GroupHeaderText:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item is GridGroupHeaderItem) { GridGroupHeaderItem groupHeader = e.Item as GridGroupHeaderItem; groupHeader.DataCell.Text = "Custom text"; }}Alternatively, you can use Templates to achieve the requested functionality:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/headerandfootertemplates/defaultcs.aspx
Hope this helps. If you have different requirements or further instructions, please elaborate on your specific scenario and send us sample screenshots or video demonstrating the desired behavior.
Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Rayne
Top achievements
Rank 1
answered on 23 Aug 2013, 01:08 PM
I've attached a screenshot of my grouping. The second grouping is using the numeric value not the text of the dropdown column. When the column is grouped, I want it to show the text, not the number.
I've been trying to use the recommended solution of using ItemBound event with e.Item.DataItem, but there is no way to tell if that is being triggered by the first grouped column or the second. So when this event is called, how do I determine which column is being grouped. In the screenshot, that 2nd grouped column isn't the only one where I'd like to customize the group header text.
Using the code above, there isn't a way to determine which column is being grouped so that I can create the appropriate header text. The code works only if I'm doing an initial grouping on PWSID. Any other grouping throws an error, as well as if I group by another group first, then try to group on PWSID column.
How do I get which column is being grouped? Is this even possible? I don't think it is.
I've been trying to use the recommended solution of using ItemBound event with e.Item.DataItem, but there is no way to tell if that is being triggered by the first grouped column or the second. So when this event is called, how do I determine which column is being grouped. In the screenshot, that 2nd grouped column isn't the only one where I'd like to customize the group header text.
if (e.Item is GridGroupHeaderItem){ var item = (GridGroupHeaderItem)e.Item; var groupDataRow = (DataRowView)e.Item.DataItem; ..... item.DataCell.Text = "PWS:" + getPwsNameFromId(groupDataRow["PWSID"].ToString());}Using the code above, there isn't a way to determine which column is being grouped so that I can create the appropriate header text. The code works only if I'm doing an initial grouping on PWSID. Any other grouping throws an error, as well as if I group by another group first, then try to group on PWSID column.
How do I get which column is being grouped? Is this even possible? I don't think it is.
0
Accepted
Hi Rayne,
You can use the following approach to determine which field belongs to the current group header:
That should do the trick.
Regards,
Eyup
Telerik
You can use the following approach to determine which field belongs to the current group header:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item is GridGroupHeaderItem) { GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; int level = groupHeader.GroupIndex.Split(new Char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).Length; GridGroupByExpression expression = RadGrid1.MasterTableView.GroupByExpressions[level - 1]; string fieldName = expression.GroupByFields[0].FieldName; }}That should do the trick.
Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Rayne
Top achievements
Rank 1
answered on 28 Aug 2013, 01:50 PM
Thank you so much! It's finally working the way I need it to.
