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

How to modify sorting behaviour ?

1 Answer 64 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 02 May 2012, 02:24 AM
This might be a simple question, but i just cant work out how to phrase what i am after so please be patient. Currently when you click on a column header, it switches between 3 modes, sort asc, desc, and 'back to default'.

My question is simple, how do i disable the 'back to default', so that once a column is sorted, it only switches between asc and desc?

1 Answer, 1 is accepted

Sort by
0
Jonathan
Top achievements
Rank 1
answered on 02 May 2012, 03:19 AM
Going to answer my question as another guy on my team worked it out. here is a behaviour for those who are after similiar functionlaity

using System.Windows.Interactivity;
using Telerik.Windows.Controls;
 
    /// <summary>
    /// Overrides the default sorting on the telerik RadGridView to enable a more prefictable user experience.
    /// </summary>
    public class GridViewCustomSortBehavior : Behavior<RadGridView>
    {
        protected override void OnAttached()
        {
            AssociatedObject.Sorting += AssociatedObjectSorting;
        }
 
        private static void AssociatedObjectSorting(object sender, GridViewSortingEventArgs e)
        {
            if (e.NewSortingState == SortingState.None)
            {
                e.NewSortingState = e.OldSortingState == SortingState.Ascending ? SortingState.Descending : SortingState.Ascending;
            }
        }
 
        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.Sorting -= AssociatedObjectSorting;
        }
    }


Tags
GridView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Jonathan
Top achievements
Rank 1
Share this question
or