We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Sorting Grouped Columns in SfDataGrid

I'm utilizing the grouping capabilities of the SfDataGrid and wanted to know is it possible to sort the grouped columns based on more than alphabetical order?

For example, if I have the following 4 groups on my grid (By default it's in alphabetical order):
  • Black
  • Orange
  • Red
  • Yellow

BUT I want it to display in this order:
  • Red
  • Yellow
  • Orange
  • Black

How would I go about doing this? In my code each color does have a number value attributed to it but I haven't figured out a way to get the grouped columns to sort the way I want.

A timely response is appreciated, thanks!

3 Replies

AN Ashok N Syncfusion Team July 2, 2015 07:35 PM UTC

Hi Ari,

Thank you for contecting syncfusion support.

We have analyzed your query and we could not understand your requirement clearly. Could you please share more details regarding your requirement, like how you are expecting the sorting when we group the column in SfDataGrid? That would be more helpful for serve you better. But you can prevent the sorting when we group the column in SfDataGrid by using SfDataGrid.View.SortDescriptions.Clear method. Please refer the below code snippet.

public MainWindow()

{

    InitializeComponent();

    this.sfDataGrid.Loaded += sfDataGrid_Loaded;

}

void sfDataGrid_Loaded(object sender, RoutedEventArgs e)

{

    var sortNotifyCollectionChanged = this.sfDataGrid.View.SortDescriptions as INotifyCollectionChanged;

    sortNotifyCollectionChanged.CollectionChanged += OnSortDescriptionsChanged;

}

private void OnSortDescriptionsChanged(object sender, NotifyCollectionChangedEventArgs e)

{

    if (this.sfDataGrid.View.SortDescriptions.Count > 0 && this.sfDataGrid.GroupColumnDescriptions.Count>0)

        this.sfDataGrid.View.SortDescriptions.Clear();

}

Sample location: http://www.syncfusion.com/downloads/support/forum/119506/ze/SimpleApplication_(2)1031239868

Please let us know if you require further assistance on this.

Thanks,

Ashok



AC Ari Case July 9, 2015 03:45 PM UTC

I'm saying how do I custom sort grouped columns?

Is there a way to sort grouped columns other than by alphabetical order dynamically? 

This was my example:

For example, if I have the following 4 groups on my grid (Alphabetical order):
  • Black
  • Orange
  • Red
  • Yellow

BUT I want it to display in this order:
  • Red
  • Yellow
  • Orange
  • Black

I just want to know how I would go about sorting grouped columns in anyway I see fit.


AN Ashok N Syncfusion Team July 10, 2015 02:44 PM UTC

Hi Ari,

We are sorry about the inconvenience caused.

We have analyzed your query and you can achieve your requirement by using custom sorting. We have prepared a sample by using custom soring and attached in the be below sample location, please refer it.

Sample location: http://www.syncfusion.com/downloads/support/forum/119506/ze/SimpleApplication-2003100714

Please refer to the following UG link to find more details on the custom sorting

UG link:  http://help.syncfusion.com/ug/wpf/index.html#!Documents/customsorting.htm

Please let us know if you require further assistance on this.

Thanks,
Ashok


Loader.
Live Chat Icon For mobile
Up arrow icon