views:

325

answers:

1

I tried to post on Telerik forum, but now each time I try to open my thread, I get "Oops... It seems there was a problem with our server." So I posted this question here.

I am pretty new to Telerik and RadGrid. I am trying to modify existing project because client needs custom sorting. There is a data field which may contain numbers or text so it is a string type but sometimes it has to be sorted as numbers. So I went to this link:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/sort/defaultcs.aspx

and http://www.telerik.com/help/aspnet-ajax/grdapplycustomsortcriteria.html

The example says:

"With custom sorting turned on, RadGrid will display the sorting icons but it will not actually sort the data." but it seems it is not enough to add AllowCustomSorting to disable default sorting.

When implementing SortCommand, I noticed that I have to do  e.Canceled = true;

because else default sorting occurs. Why this is not mentioned in the documentation nor example?

But the main question is - inside of SortCommand my RadGrid already has all items loaded. So is there any way to sort them to avoid hitting database? I tried accessing various Items properties of both "object source, GridSortCommandEventArgs e", but all Items are read-only, so I cannot sort them and attach back to the RadGrid.

Thanks for any ideas.

A: 

You can set the sortExpression in the OnSelecting event of the objectDatasource and use it in the SelectMethod.

protected void odsGridData_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
   e.InputParameters["filterExpression"] = grdMyTasks.MasterTableView.FilterExpression;
   //Set the Sort Expression and use this in the Get method
   e.InputParameters["sortExpression"] = grdMyTasks.MasterTableView.SortExpressions.GetSortString();
   e.Arguments.StartRowIndex = grdMyTasks.CurrentPageIndex;
   e.Arguments.MaximumRows = grdMyTasks.PageSize;
}

This way you can perform custom sort and pass on the data to the RadGrid.

Hope this helps.

dhinesh