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

GridView - Column Sorting

1 Answer 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frustrated Dev
Top achievements
Rank 1
Frustrated Dev asked on 08 Mar 2010, 05:28 PM
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,

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 09 Mar 2010, 08:15 AM
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.
Tags
GridView
Asked by
Frustrated Dev
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or