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

Radgrid group cannot be sorted

1 Answer 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fali
Top achievements
Rank 1
Fali asked on 08 Jan 2014, 07:50 AM
I have a telerik radgrid in my application as below and related codes for binding. My Problem is eventhough I have set my GroupByFields SortOrder = "Descending" it still in ascending mode. Is there anything wrong in my code? [this is developed by previous developer and I'm new for telerik controls]. Please advice. Thanks in advance.
Dim tblTable As DataTable = DirectCast(ViewState("dtTblData"), DataTable)
         
''some codes ...
 
ViewState("dtTblData") = tblTable
rgInvoiceList.DataSource = tblTable
Try
     Dim expression1 As GridGroupByExpression = GridGroupByExpression.Parse("ClaimsFor [Claims Type], count(ClaimsFor) Items [My Items], Sum(Total) [Group Total] Group By ClaimsFor")
     Me.CustomizeExpression(expression1)
          Me.rgInvoiceList.MasterTableView.GroupByExpressions.Add(expression1)
          rgInvoiceList.Rebind()
Catch ex As Exception
            Console.WriteLine("error" & ex.Message)
Finally
End Try
<telerik:RadGrid ID="rgInvoiceList" runat="server" CellSpacing="0" GridLines="None" ShowFooter="True" Skin="Hay" AllowSorting="True">
     <ClientSettings EnablePostBackOnRowClick="True">
          <Selecting CellSelectionMode="None" AllowRowSelect="True"></Selecting>
     </ClientSettings>
     <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID" AllowCustomSorting="true">
          <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
          <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
               <HeaderStyle Width="20px"></HeaderStyle>
          </RowIndicatorColumn>
          <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
               <HeaderStyle Width="20px"></HeaderStyle>
          </ExpandCollapseColumn>
          <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
          </EditFormSettings>
          <GroupByExpressions>
               <telerik:GridGroupByExpression>
                    <SelectFields>
                         <telerik:GridGroupByField FieldName="Total"/>
                    </SelectFields>
                    <GroupByFields>
                         <telerik:GridGroupByField FieldName="ClaimsFor" SortOrder="Descending"/>
                    </GroupByFields>
               </telerik:GridGroupByExpression>
          </GroupByExpressions>
     </MasterTableView>
     <FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jan 2014, 09:56 AM
Hi Fali,

Please try the below sample code snippet to have RadGrid grouped in Descending. Make sure you are binding the RadGrid in the NeedDataSource event.

ASPX:
<telerik:RadGrid ID="rgInvoiceList" runat="server" Skin="Hay" OnItemDataBound="rgInvoiceList_ItemDataBound"
    OnNeedDataSource="rgInvoiceList_NeedDataSource">
    <ClientSettings>
        <Selecting AllowRowSelect="True"></Selecting>
    </ClientSettings>
    <MasterTableView DataKeyNames="CustomerID" ClientDataKeyNames="CustomerID" AllowCustomSorting="true">
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="CustomerID" />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="ContactTitle" SortOrder="Descending" />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub rgInvoiceList_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    Dim dt As New DataTable()
    dt.Columns.Add("CustomerID", GetType(String))
    dt.Columns.Add("ContactTitle", GetType(String))
    For i As Integer = 0 To 4
        dt.Rows.Add("CustomerID" + i, "Sales Representative")
    Next
    For i As Integer = 6 To 8
        dt.Rows.Add("CustomerID" + i, "Owner/Marketing Assistant")
    Next
    For i As Integer = 10 To 15
        dt.Rows.Add("CustomerID" + i, " Accounting Manager")
    Next
    rgInvoiceList.DataSource = dt
End Sub
Protected Sub rgInvoiceList_ItemDataBound(sender As Object, e As GridItemEventArgs)
    Dim expression = GridGroupByExpression.Parse("ContactTitle [ContactTitle], count(CustomerID)  Group By ContactTitle")
    rgInvoiceList.MasterTableView.GroupByExpressions.Add(expression)
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Fali
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or