Grouping

6 posts, 0 answers
  1. Paula
    Paula avatar
    13 posts
    Member since:
    Jun 2012

    Posted 12 Jul 2010 Link to this post

    I'm trying to do a simple grouping in my grid but I cannot figure out what I am missing.  All I want in my group "header" i guess it would be called is the field name but for some reason it is coming out [field_title]: [field_name].  When can I remove the field_title and only show field_name?

     

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"

     

     

    DataSourceID="sqlCategories" GridLines="None">

     

    <

     

    MasterTableView DataKeyNames="Main_Category_ID,Sub_Category_ID"

     

     

    DataSourceID="sqlCategories">

     

    <

     

    RowIndicatorColumn>

     

    <

     

    HeaderStyle Width="20px"></HeaderStyle>

     

    </

     

    RowIndicatorColumn>

     

    <

     

    ExpandCollapseColumn>

     

    <

     

    HeaderStyle Width="20px"></HeaderStyle>

     

    </

     

    ExpandCollapseColumn>

     

     

    <Columns>

     

     

    <telerik:GridBoundColumn DataField="Main_Category"

     

     

    SortExpression="Main_Category" UniqueName="Main_Category" Visible="False">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="Sub_Category" HeaderText="Sub_Category"

     

     

    SortExpression="Sub_Category" UniqueName="Sub_Category">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="Sub_Category_Desc"

     

     

    HeaderText="Sub_Category_Desc" SortExpression="Sub_Category_Desc"

     

     

    UniqueName="Sub_Category_Desc">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="Main_Category_ID" DataType="System.Int32"

     

     

    HeaderText="Main_Category_ID" ReadOnly="True" SortExpression="Main_Category_ID"

     

     

    UniqueName="Main_Category_ID">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="Sub_Category_ID" DataType="System.Int32"

     

     

    HeaderText="Sub_Category_ID" ReadOnly="True" SortExpression="Sub_Category_ID"

     

     

    UniqueName="Sub_Category_ID">

     

     

    </telerik:GridBoundColumn>

     

     

    </Columns>

     

     

    <GroupByExpressions>

     

     

    <telerik:GridGroupByExpression>

     

     

    <SelectFields>

     

     

    <telerik:GridGroupByField FieldAlias="Main_Category" FieldName="Main_Category" FormatString="{0}"></telerik:GridGroupByField>

     

     

    </SelectFields>

     

     

    <GroupByFields>

     

     

    <telerik:GridGroupByField FieldName="Main_Category" SortOrder="Descending"></telerik:GridGroupByField>

     

     

    </GroupByFields>

     

     

    </telerik:GridGroupByExpression>

     

     

    </GroupByExpressions>

     

    </

     

    MasterTableView>

     

     

    </telerik:RadGrid>

     

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Jul 2010 Link to this post

    Hello Paula,

    Try the following code snippet in ItemDataBound event to hide the field title in GroupHeader.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
           if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item;
                groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1];
            }
         }

    Also refer the following documentation which expalins how to customize GridGroupHeaderItem.
    Customizing GridGroupHeaderItem

    Thanks,
    Princy.

  3. Paula
    Paula avatar
    13 posts
    Member since:
    Jun 2012

    Posted 13 Jul 2010 Link to this post

    Thanks Princy, that worked!
  4. Espen Fosshaug
    Espen Fosshaug avatar
    18 posts
    Member since:
    Sep 2009

    Posted 16 Sep 2010 Link to this post

    Hi.

    This is working, but I have two levels of grouping and need to change the text in the headers differently.
    With this approach each sublevel have the same changed text.

    Tried this:
    foreach (DataColumn column in groupDataRow.DataView.Table.Columns)
    {
        if (column.ColumnName == "MainGroupName")
        {
            item.DataCell.Text = groupDataRow["MainGroupName"].ToString();
        }
        else
        {
            item.DataCell.Text = "Ordrenr.:" + groupDataRow["OrderCopyNo"].ToString() + " Vår ref.:" + groupDataRow["EmployeeName"].ToString() + "";
        }

    But they are still changed the same way. Is there any way I can find which grouping level I am in on databound and then change them differently?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Sep 2010 Link to this post

    Hello Espen,

    Try the following code snippet to set different header text for each level of grouping.

    ASPX:
    <GroupByExpressions>
        <telerik:GridGroupByExpression>
            <SelectFields>
                <telerik:GridGroupByField FieldName="user_role" HeaderText="user_role" />
            </SelectFields>
            <GroupByFields>
                <telerik:GridGroupByField FieldName="user_role" SortOrder="Descending" />
            </GroupByFields>
        </telerik:GridGroupByExpression>
        <telerik:GridGroupByExpression>
            <SelectFields>
                <telerik:GridGroupByField FieldName="FirstName" HeaderText="FirstName" />
            </SelectFields>
            <GroupByFields>
                <telerik:GridGroupByField FieldName="FirstName" SortOrder="Descending" />
            </GroupByFields>
        </telerik:GridGroupByExpression>
    </GroupByExpressions>

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
      {
          if (e.Item is GridGroupHeaderItem)
          {
              GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item;
              if (groupHeader.DataCell.Text.Split(':')[0] == "user_role")
                  groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1];
              else
                  groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1];
          }
      }

    Thanks,
    Princy.
  6. Espen Fosshaug
    Espen Fosshaug avatar
    18 posts
    Member since:
    Sep 2009

    Posted 17 Sep 2010 Link to this post

    Thanks Princy.

    Worked like a charm!

    Espen
Back to Top