How to modify sorting behaviour ?

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    8 posts
    Member since:
    Jun 2009

    Posted 01 May 2012 Link to this post

    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?
  2. Jonathan
    Jonathan avatar
    8 posts
    Member since:
    Jun 2009

    Posted 01 May 2012 Link to this post

    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;
            }
        }


Back to Top