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

Sort column sorts ascending but shows desecnding arrow

3 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 17 Mar 2014, 07:53 PM
I have a grid with a detail table that needed a custom sort. the custom sort works fine. I created an if-else to do a regular sort on the main table.
preclick:
column A
b
d
a

 When I click on a column in the main table the first time it sorts acending but the sort arrow points down.
column A v
a
b
d

I click again and the OldSortOrder is decsending just like the arrow which makes the NewSortOrder a no sort but the arrow is no pointing up.
column A ^
a
b
d

I click again and the OldSortOrder is ascending, NewSortOrder is descending and so is the grid but now there is no arrow.
column A
d
b
a


Any clues?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Mar 2014, 07:14 AM
Hi Fred,

Its hard to identify the issue with so less information. Please take a look at this demo on Grid - Custom Sorting and try to replicate the issue. If this doesn't help, provide your full code snippet.

Thanks,
Shinu
0
Fred
Top achievements
Rank 1
answered on 18 Mar 2014, 12:25 PM
I have three other grids on the page with virtually the same code and all work.

It looks to me that when the column is clicked the sort code gets called the grid gets sorted then somehow the GridSortCommand sortorder gets changed to the next sort order, then the screen gets painted. Does that ring any bells?
0
Shinu
Top achievements
Rank 2
answered on 19 Mar 2014, 08:36 AM
Hi Fred,

Please try the below sample code snippet. Provide your code snippet for further help.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" AllowPaging="true"  AllowSorting="true" OnSortCommand="RadGrid1_SortCommand" >
    <MasterTableView DataKeyNames="OrderID" AllowCustomSorting="true">
        <Columns>
          <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID"/>
          <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>" SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

C#:
protected void RadGrid1_SortCommand(object sender, GridSortCommandEventArgs e)
{
 GridSortExpression sortExpr = new GridSortExpression();
 switch (e.OldSortOrder)
 {
     case GridSortOrder.None:
         sortExpr.FieldName = e.SortExpression;
         sortExpr.SortOrder = GridSortOrder.Descending;
         e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
         break;
     case GridSortOrder.Ascending:
         sortExpr.FieldName = e.SortExpression;
         sortExpr.SortOrder = RadGrid1.MasterTableView.AllowNaturalSort ? GridSortOrder.None : GridSortOrder.Descending;
         e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
         break;
     case GridSortOrder.Descending:
         sortExpr.FieldName = e.SortExpression;
         sortExpr.SortOrder = GridSortOrder.Ascending;
         e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
         break;
 }
 
 e.Canceled = true;
 RadGrid1.Rebind();
 
 if (!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression))
 {
     sortExpr.FieldName = e.SortExpression;
     sortExpr.SortOrder = GridSortOrder.Ascending;
     e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
 }
}

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