2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
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:
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.
This page will automatically be redirected to the sign-in page in 10 seconds.
I programmed like the above code but when dataGrid.IsVisible = false the application crash, do you have a way to fix it? error"object null" private async void HeaderView_ClickedButton(object sender, EventArgs e) { LoadView.IsVisible = true; var vm = (CashStatementPageViewModel)BindingContext; var checklist = await vm.GetListCashStament(); if (checklist) { dataGrid.View.BeginInit(); var groupColumn = dataGrid.View.SortDescriptions.FirstOrDefault(x => x.PropertyName == "Group"); dataGrid.View.SortDescriptions.Remove(groupColumn); dataGrid.View.EndInit(); } LoadView.IsVisible = false; } I use code after "checklist" have data, don't use the code in DataGrid_GridViewCreate like you