GridView - Column Sorting

2 posts, 0 answers
  1. Frustrated Dev
    Frustrated Dev avatar
    35 posts
    Member since:
    Oct 2006

    Posted 08 Mar 2010 Link to this post

    Hello,

    I have a RadGridView in my application. Currently, this RadGridView is allowing users to sort by multiple columns. However, I do not want mult-sort enabled. However, it appears that it is enabled by default.

    1. Is multi-sort enabled by default?
    2. If so, how do I disable multi-sort?
    3. If not, what properties are associated with sorting? I just want to sort by one column at a time.

    Thank you,
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 09 Mar 2010 Link to this post

    Hi Frustrated Dev,

    The CanUserSortColumns property is used to allow or disallow sorting from the UI and this property is set to true by default. For the time being there is no distinction between multiple and single sorting and if sorting is enabled, multiple sorting is enabled as well. Luckily you can disable multiple sorting with just a few lines of code:

    public MainPage()
    {
        InitializeComponent();
      
        this.playersGrid.ItemsSource = Club.GetPlayers();
      
        // true by default
        this.playersGrid.CanUserSortColumns = true;
        this.playersGrid.Sorting += new System.EventHandler<GridViewSortingEventArgs>(playersGrid_Sorting);
    }
      
    void playersGrid_Sorting(object sender, GridViewSortingEventArgs e)
    {
        if (this.playersGrid.SortDescriptors.Count >= 1 && 
            this.playersGrid.SortDescriptors[0].Member != e.SortPropertyName)
        {
            // if grid is already sorted - cancel pending sort request
      
            e.NewSortingState = SortingState.None;
            e.Cancel = true;
        }
    }

    Hope this helps.


    All the best,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top