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

RadGrid, default sort is lost on grid update

2 Answers 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gavin Pollock
Top achievements
Rank 1
Gavin Pollock asked on 21 Aug 2014, 04:55 PM
Hello guys,

I am using the RadGrid component in order to display my data: ideally I would like to sort the item by the field "EventID" and I've used the following code in order to achieve that:

<SortExpressions>
        <telerik:GridSortExpression FieldName="EventID" SortOrder="Descending" />
 </SortExpressions>

Which works just fine.

In my scenario I am editing one of the grid item in a modal window and, when the item is submitted,  I want to refresh the parent page who contains the grid.  

In order to do that I am using the following code:

RadAjaxManager manager = RadAjaxManager.GetCurrent(this.Page);
manager.ResponseScripts.Add("CloseWindowReload('" + gridReloadCommand + "','" + ((itemID == null) ? "-1" : itemID.ToString()) + "');");

Which does refresh the parent page and the grid correctly, but the latter is not sorted by descending anymore . 

Do you have any advice for me?

Regards
Gavin


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 22 Aug 2014, 06:12 AM
Hi Gavin Pollock,

Try setting the sort expression from code behind in the PreRender event as follows :

C#:
protected void SampleGrid_PreRender(object sender, EventArgs e)
{
    GridSortExpression sortExpression = new GridSortExpression();
    sortExpression.FieldName = "EventID";
    sortExpression.SortOrder = GridSortOrder.Descending;
    SampleGrid.MasterTableView.SortExpressions.Add(sortExpression);
    SampleGrid.MasterTableView.Rebind();
}

Thanks,
Shinu
0
Gavin Pollock
Top achievements
Rank 1
answered on 22 Aug 2014, 12:48 PM
That worked perfectly, thank you very much Shinu!
Tags
Grid
Asked by
Gavin Pollock
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Gavin Pollock
Top achievements
Rank 1
Share this question
or