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

RadGrid GroupBy Problem

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 10 Jan 2011, 06:28 PM
I am using a RadGrid and doing group by with jobstateName but when I bind the data my last stage comes first with users.
For example:

I have four stages (stage1, stage2, stage3, stage4)
and i want that when i bind the data my stage1 appears first with their respective users but right now it is appearing in the descending order like
stage4, stage3, stage2 and stage1

I also don't want that my jobStateName appears at the header of the grid  ....

  <telerik:RadGrid ID="gvUserJobMapping" runat="server" PageSize="10" AllowSorting="True"
            GroupingEnabled="true" AllowPaging="True" ShowGroupPanel="True" AutoGenerateColumns="False"
            GridLines="None" CssClass="gridviewSpacing gvJobStates">
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView Width="50%" GroupLoadMode="Client" TableLayout="Fixed">
                <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldName="JobStateName" FieldAlias="JobStateName" HeaderText="Job Stages"
                                FormatString="{0:D}"></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="JobStateName" FieldAlias="JobStateName" HeaderText="Job Stages"
                                ></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="JobID" HeaderText="JobID" HeaderButtonType="TextButton"
                        DataField="JobID" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="JobStateID" HeaderText="JobStateID" HeaderButtonType="TextButton"
                        DataField="JobStateID" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="JobID" HeaderText="JobID" HeaderButtonType="TextButton"
                        DataField="JobID" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="UserID" HeaderText="UserID" HeaderButtonType="TextButton"
                        DataField="UserID" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="RoleID" HeaderText="RoleID" HeaderButtonType="TextButton"
                        DataField="RoleID" Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="UserName" HeaderText="User Name" HeaderButtonType="TextButton"
                        DataField="UserName">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkSendEmail" runat="server"></asp:CheckBox>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings AllowGroupExpandCollapse="True" ReorderColumnsOnClient="True" AllowDragToGroup="False"
                AllowColumnsReorder="True">
            </ClientSettings>
        </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Jan 2011, 07:44 AM
Hello Muhammad,

Try to set  the SortOrder as 'Ascending'  for the GroupByFields in GroupByExpressions .

ASPX:
<GroupByFields>
   <telerik:GridGroupByField FieldName="JobStateName" FieldAlias="JobStateName"
       HeaderText="Job Stages" SortOrder="Ascending">
   </telerik:GridGroupByField>
</GroupByFields>

And in oder to hide the Field name in Group header, try the following code snippet in ItemDataBound event:

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].ToString() ;
     }
   }
  }

Thanks,
Princy.
0
Muhammad
Top achievements
Rank 1
answered on 11 Jan 2011, 06:32 PM
Thank you for your reply but stages are still appearing in the descending order I am binding my grid with the datatable but I am also using order by asc. I don't why my stages are appearing in the descending order.

I have used the code and now just my stage names appear with my users.
I also don't want that in my header it appears the jobstatename because i don't want it to show to the end-user that I am grouping with the JobStateName.

Because jobstatename appears at the top and it looks very ugly in my scenario.
Tags
Grid
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Muhammad
Top achievements
Rank 1
Share this question
or