)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: Xamarin.Forms |
Control: SfDataGrid |
Published Date: July 14, 2017 |
Last Revised Date: March 26, 2020 |
Product Version: 13.4.0.53
Tags: grouping

By default, SfDataGrid groups a column in the sorted order. However, you can group a column in the actual order without sorting the groups in SfDataGrid by removing the grouped column from the SfDataGrid.View.SortDescriptions in the SfDataGrid.GridViewCreated event.  

Please refer the below code example to group a column in the actual order without sorting.

MainPage.cs

public partial class MainPage : ContentPage
{
        private SfDataGrid dataGrid;
        private ViewModel viewModel;
        public MainPage()
        {
            InitializeComponent();
            dataGrid = new SfDataGrid();
            viewModel = new ViewModel();
            dataGrid.ItemsSource = viewModel.OrdersInfo;
            dataGrid.GridViewCreated += DataGrid_GridViewCreated;
            dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "CustomerID" });
            this.Content = dataGrid ;
        }
        private void DataGrid_GridViewCreated(object sender, GridViewCreatedEventArgs e)
        {
            dataGrid.View.BeginInit();
            var groupColumn = dataGrid.View.SortDescriptions.FirstOrDefault(x => x.PropertyName == "CustomerID");
            dataGrid.View.SortDescriptions.Remove(groupColumn);
            dataGrid.View.EndInit();
        }
}            

 

Screenshot:

C:\Users\pavithra.sivakumar\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Screenshot_2017-07-08-23-05-30.png

 

Note:

In case, if you are applying grouping in runtime, then you have to apply the same logic of removing the grouped column from SfDataGrid.View.SortDescriptions after applying grouping to achieve this requirement.

 

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

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon