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

fromat group header

4 Answers 311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 08 Aug 2008, 08:16 PM
I have a grid with the following GroupByexpressions. Instead of the group header showing "State: XX; Count: YYY" as it does now, I would like for it to simply show "State: XX (YYY)". Can anyone give me a hand in modifying the expressions to achieve this?

<

GroupByExpressions>

<telerik:GridGroupByExpression>

<SelectFields>

<telerik:GridGroupByField FieldAlias="State" FieldName="GroupState"></telerik:GridGroupByField>

<telerik:GridGroupByField FieldAlias="Count" Aggregate="Count" FieldName="ID" />

</SelectFields>

<GroupByFields>

<telerik:GridGroupByField FieldName="GroupState" HeaderText="State"></telerik:GridGroupByField>

</GroupByFields>

</telerik:GridGroupByExpression>

</GroupByExpressions>

4 Answers, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 10 Aug 2008, 03:26 AM
Hello Albert,

You can definitely have the RadGrid display the Group headers in the format you want, you just have to know which properties to set. First, in your <SelectFields> you need to set the HeaderText of the aggregate field to the string " " in order to keep it from displaying. This property's default value is the FieldName, which it will display if not set or if set with an empty string. Once you get rid of the HeaderText you also want to do the same with the HeaderValueSeparator by setting it to the string " " as well. This will keep the colon ":" from being displayed. In order to display the aggregate field's value in parenthesis, you can use the FormatString property, setting it to "({0})". Finally, in the RadGrid's <GroupSettings> properties, set the GroupByFieldsSeparator property to an empty string ("") in order to get rid of the semicolon. Having done all this you should see the header for each group display in the format you want.

Here is an example:

<telerik:RadGrid ID="RadGrid1" runat="server"    
    OnNeedDataSource="RadGrid1_NeedDataSource"
        <GroupingSettings GroupByFieldsSeparator="" /> 
        <MasterTableView> 
            <GroupByExpressions> 
                <telerik:GridGroupByExpression> 
                    <SelectFields> 
                        <telerik:GridGroupByField FieldAlias="State" FieldName="State" FormatString="{0}" /> 
                        <telerik:GridGroupByField FieldName="ID"  
                            Aggregate="Count"  
                            FormatString="({0})"  
                            HeaderValueSeparator=" "  
                            HeaderText=" " /> 
                    </SelectFields> 
                    <GroupByFields> 
                        <telerik:GridGroupByField FieldName="State" /> 
                    </GroupByFields> 
                </telerik:GridGroupByExpression> 
            </GroupByExpressions> 
        </MasterTableView> 
</telerik:RadGrid> 

I hope this helps. If you have any further questions, please don't hesitate to ask.

Sincerely,
Kevin Babcock
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 10 Aug 2008, 04:04 AM
That worked perfectly, Kevin. Thanks for your help!
0
Dhawal
Top achievements
Rank 1
answered on 23 Dec 2008, 12:18 PM
hi Kevin,

i ran into a similar issue with a minor difference that i am binding the value in the group by column to an enumeration which displays appropriate value from the enum. the format string property does not have this bind method. hope u can help me on this below is the sample code:

<GroupByExpressions>
                        <telerik:GridGroupByExpression>  
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="CategoryType" FieldName="CategoryType"></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldAlias="CategoryType" FieldName="CategoryType"></telerik:GridGroupByField>
                        </GroupByFields>              
                        </telerik:GridGroupByExpression>
                    </GroupByExpressions>

I want to set it as it is displayed in the template column:

<telerik:GridTemplateColumn ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="Center" DataField="CategoryType" HeaderText="Category Type" SortExpression="CategoryType"
                            UniqueName="CategoryType" EditFormColumnIndex="1">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblCategoryType"  Text='<%# (Convert.ToInt32(Eval("CategoryType"))== 1) ? CategoryType.Main : CategoryType.Additional %>'></asp:Label>
                            </ItemTemplate>                            
                        </telerik:GridTemplateColumn>
If 1 it displays main and 2 then additional and vice versa.

ur efforts are appreciated.



0
Dhawal
Top achievements
Rank 1
answered on 23 Dec 2008, 01:31 PM
Got the solution in the below post

http://www.telerik.com/help/aspnet/grid/grdperformcalculationsingroupheader.html
Tags
Grid
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
Kevin Babcock
Top achievements
Rank 1
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Dhawal
Top achievements
Rank 1
Share this question
or