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

Custom Sorting on RadGridView

1 Answer 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Akhil Dwivedi
Top achievements
Rank 1
Akhil Dwivedi asked on 04 Dec 2009, 07:05 AM
Hi,

I am unable to find OldSortingState & NewSortingState properties in GridViewSortingEventArgs.. Follwing is your example, Please suggest

private
void CustomSortingGrid_Sorting( object sender, GridViewSortingEventArgs e )
{
   
//Gets the value of the ItemsSource property as IEnumerable.
   
IEnumerable<Employee> employees = e.DataControl.ItemsSource as IEnumerable<Employee>;
   
//Checks if the value of the collection is null.
   
if ( employees == null )
   {
       e.Cancel = true;
       
return;
   }
   
//If the sorting state is none, sort the items ascending.
   
if ( e.OldSortingState == SortingState.None )
   {
       e.NewSortingState = SortingState.Ascending;
       employees = employees.OrderBy( employee => employee.GetType()
                                                          .GetProperty( e.SortPropertyName )
                                                          .GetValue( employee,
null ) );
   }
   
//If the sorting state is none, sort the items descending.
   
else if ( e.OldSortingState == SortingState.Ascending )
   {
       e.NewSortingState = SortingState.Descending;
       employees = employees.OrderByDescending( employee => employee.GetType()
                                                                    .GetProperty( e.SortPropertyName )
                                                                    .GetValue( employee,
null ) );
   }
   
//If the sorting state is descending, apply default sorting to the items.
   
else
   {
       
e.NewSortingState = SortingState.None;
       employees = employees.OrderBy( employee => employee.EmployeeID );
   }
   
//Set the sorted collection as source of the RadGridView
   
e.DataControl.ItemsSource = employees.ToList();
   e.Cancel = true;
}

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 04 Dec 2009, 07:19 AM
Hello,

You may need to download our latest version.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Akhil Dwivedi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or