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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sorting Grouped Columns in SfDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

119506 Jul 1,2015 02:34 PM UTC Jul 10,2015 02:44 PM UTC WPF 3
loading
Tags: SfDataGrid
Ari Case
Asked On July 1, 2015 02:34 PM UTC

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!

Ashok N [Syncfusion]
Replied On 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


Ari Case
Replied On 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.

Ashok N [Syncfusion]
Replied On 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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;