How to group a column in the actual order without sorting the data in SfDataGrid?

How can I group a column in the actual order without sorting the data in SfDataGrid?

I can find article regarding the same Xamarin.Forms https://www.syncfusion.com/kb/7852/how-to-group-a-column-in-the-actual-order-without-sorting-the-data-in-sfdatagrid but I cannot get it to work for WinUI.


1 Reply 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team March 13, 2023 01:49 PM UTC

Hi Phil,

Your requirement to “Group a column in the actual order without sorting the data” will be achievable by removing the grouped columns from the SortDescriptions shown below,

this.sfDataGrid.Loaded += OnSfDataGridLoaded;

private void OnSfDataGridLoaded(object sender, RoutedEventArgs e)

{

    this.sfDataGrid.View.CurrentChanged += OnCurrentVoewChanged;

}

 

private void OnCurrentVoewChanged(object sender, object e)

{

    // Get the grouped column

    var groupColumn = sfDataGrid.View.SortDescriptions.FirstOrDefault(x => x.PropertyName == "CustomerID");

 

    // Remove the grouped column from the SortDescriptions

    if (sfDataGrid.SortColumnDescriptions.FirstOrDefault(x => x.ColumnName == "CustomerID") != null)

        sfDataGrid.View.SortDescriptions.Remove(groupColumn);

}


Here we have prepared the sample for your reference, please have a look at this.

Regards,

Dhanasekar M.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDataGrid_WinUI_5adafb36.zip

Marked as answer
Loader.
Up arrow icon