How to group a column in the actual order without sorting the data in SfDataGrid?
By default, Xamarin DataGrid 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:
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?
I hope you enjoyed learning about how to group a column in the actual order without sorting the data in SfDataGrid.
You can refer to our Xamarin DataGrid’s feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin DataGrid documentation to understand how to present and manipulate data.
For current customers, you can check out our Xamarin components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Xamarin DataGrid and other Xamarin components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!