fromat group header

5 posts, 0 answers
  1. Albert Shenker
    Albert Shenker avatar
    550 posts
    Member since:
    Mar 2004

    Posted 08 Aug 2008 Link to this post

    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>

  2. Kevin Babcock
    Kevin Babcock avatar
    189 posts
    Member since:
    Mar 2007

    Posted 09 Aug 2008 Link to this post

    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:

    1 <telerik:RadGrid ID="RadGrid1" runat="server"    
    2     OnNeedDataSource="RadGrid1_NeedDataSource"
    3         <GroupingSettings GroupByFieldsSeparator="" /> 
    4         <MasterTableView> 
    5             <GroupByExpressions> 
    6                 <telerik:GridGroupByExpression> 
    7                     <SelectFields> 
    8                         <telerik:GridGroupByField FieldAlias="State" FieldName="State" FormatString="{0}" /> 
    9                         <telerik:GridGroupByField FieldName="ID"  
    10                             Aggregate="Count"  
    11                             FormatString="({0})"  
    12                             HeaderValueSeparator=" "  
    13                             HeaderText=" " /> 
    14                     </SelectFields> 
    15                     <GroupByFields> 
    16                         <telerik:GridGroupByField FieldName="State" /> 
    17                     </GroupByFields> 
    18                 </telerik:GridGroupByExpression> 
    19             </GroupByExpressions> 
    20         </MasterTableView> 
    21 </telerik:RadGrid> 

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

    Sincerely,
    Kevin Babcock
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Albert Shenker
    Albert Shenker avatar
    550 posts
    Member since:
    Mar 2004

    Posted 09 Aug 2008 Link to this post

    That worked perfectly, Kevin. Thanks for your help!
  5. Dhawal
    Dhawal avatar
    4 posts
    Member since:
    Oct 2008

    Posted 23 Dec 2008 Link to this post

    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.



  6. Dhawal
    Dhawal avatar
    4 posts
    Member since:
    Oct 2008

    Posted 23 Dec 2008 Link to this post

    Got the solution in the below post

    http://www.telerik.com/help/aspnet/grid/grdperformcalculationsingroupheader.html
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017