|
1 |
| -# How-to-reset-sorting-and-grouping-programmatically-in-.NET-MAUI-DataGrid-SfDataGrid |
2 |
| -This demo shows how to reset sorting and grouping programmatically in .NET MAUI DataGrid (SfDataGrid) |
| 1 | +# How to reset sorting and grouping in .NET MAUI DataGrid SfDataGrid? |
| 2 | +This article shows how to reset sorting and grouping in Syncfusion [.NET MAUI DataGrid](https://help.syncfusion.com/maui/datagrid/overview) (`SfDataGrid`). It demonstrates how a user can cancel sorting and return to its original state programmatically. Similarly, grouping can also be reset programmatically. |
| 3 | + |
| 4 | +## Xaml |
| 5 | +``` |
| 6 | +<ContentPage.BindingContext> |
| 7 | + <local:ViewModel /> |
| 8 | +</ContentPage.BindingContext> |
| 9 | +<Grid ColumnDefinitions="*,200" ColumnSpacing="5" Padding="10"> |
| 10 | + <VerticalStackLayout HorizontalOptions="Center" Grid.Column="1" VerticalOptions="Center" Spacing="10"> |
| 11 | + <Button Text="Allow Sorting" |
| 12 | + Clicked="Button_Clicked" |
| 13 | + WidthRequest="150"/> |
| 14 | + <Button Text="Clear Sorting" |
| 15 | + Clicked="Button_Clicked_1" |
| 16 | + WidthRequest="150"/> |
| 17 | + <Button Text="Allow Grouping" |
| 18 | + Clicked="Button_Clicked_2" |
| 19 | + WidthRequest="150"/> |
| 20 | + <Button Text="Clear Grouping" |
| 21 | + Clicked="Button_Clicked_3" |
| 22 | + WidthRequest="150"/> |
| 23 | + </VerticalStackLayout> |
| 24 | + <syncfusion:SfDataGrid x:Name="datagrid" |
| 25 | + Grid.Column="0" |
| 26 | + ColumnWidthMode="Fill" |
| 27 | + ItemsSource="{Binding OrderList}"> |
| 28 | + <syncfusion:SfDataGrid.Columns> |
| 29 | + <syncfusion:DataGridNumericColumn MappingName="OrderID" HeaderText="Order ID"/> |
| 30 | + <syncfusion:DataGridTextColumn MappingName="CustomerID" HeaderText="Customer ID"/> |
| 31 | + <syncfusion:DataGridDateColumn MappingName="ShippingDate" HeaderText="Order Date"/> |
| 32 | + <syncfusion:DataGridNumericColumn MappingName="SupplierID" HeaderText="Supplier ID"/> |
| 33 | + <syncfusion:DataGridTextColumn MappingName="ShipCity" HeaderText="Shipping City"/> |
| 34 | + <syncfusion:DataGridTextColumn MappingName="ShipCountry" HeaderText="Shipping Country"/> |
| 35 | + <syncfusion:DataGridNumericColumn MappingName="Freight" HeaderText="Freight"/> |
| 36 | + </syncfusion:SfDataGrid.Columns> |
| 37 | + </syncfusion:SfDataGrid> |
| 38 | +</Grid> |
| 39 | +</ContentPage.Content> |
| 40 | +``` |
| 41 | + |
| 42 | +## Xaml.cs |
| 43 | +``` |
| 44 | +public partial class MainPage : ContentPage |
| 45 | +{ |
| 46 | + public MainPage() |
| 47 | + { |
| 48 | + InitializeComponent(); |
| 49 | + } |
| 50 | +
|
| 51 | + private void Button_Clicked(object sender, EventArgs e) |
| 52 | + { |
| 53 | + datagrid.SortingMode = Syncfusion.Maui.DataGrid.DataGridSortingMode.Multiple; |
| 54 | + } |
| 55 | +
|
| 56 | + private void Button_Clicked_1(object sender, EventArgs e) |
| 57 | + { |
| 58 | + datagrid.SortColumnDescriptions.Clear(); |
| 59 | + } |
| 60 | +
|
| 61 | + private void Button_Clicked_2(object sender, EventArgs e) |
| 62 | + { |
| 63 | + datagrid.GroupingMode = Syncfusion.Maui.DataGrid.GroupingMode.Multiple; |
| 64 | + datagrid.GroupColumnDescriptions.Add(new GroupColumnDescription() |
| 65 | + { |
| 66 | + ColumnName = "ShipCountry", |
| 67 | + }); |
| 68 | + datagrid.GroupColumnDescriptions.Add(new GroupColumnDescription() |
| 69 | + { |
| 70 | + ColumnName = "ShipCity", |
| 71 | + }); |
| 72 | + } |
| 73 | +
|
| 74 | + private void Button_Clicked_3(object sender, EventArgs e) |
| 75 | + { |
| 76 | + datagrid.GroupColumnDescriptions.Clear(); |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +### ScreenShot |
| 82 | + |
| 83 | +Here is the expected output when executing the sample: |
| 84 | + |
| 85 | +#### Sorting |
| 86 | + |
| 87 | +<img src="https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjQyMzAwIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.PHG6_nN9qmCkMpo3S_Fwk9Vh3nYUJR4xVxUmCGz2His" height = 396/> |
| 88 | + |
| 89 | +#### Grouping |
| 90 | + |
| 91 | +<img src="https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjQyMjk5Iiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.Ry0vtZWWfNxlyvUn4-mDkjTnRYOOSuA_gm5bz-QcTvs" height = 396/> |
| 92 | + |
| 93 | +View sample in [GitHub](https://github.com/SyncfusionExamples/How-to-reset-sorting-and-grouping-programmatically-in-.NET-MAUI-DataGrid-SfDataGrid) |
| 94 | + |
| 95 | + Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid). |
| 96 | + |
| 97 | +### Conclusion |
| 98 | +I hope you enjoyed learning about How to implement select all checkbox column in SfDataGrid. |
| 99 | + |
| 100 | +You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our [.NET MAUI DataGrid Documentation](https://help.syncfusion.com/maui/datagrid/getting-started) to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) to explore our .NET MAUI DataGrid and other .NET MAUI components. |
| 101 | + |
| 102 | +If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums),[Direct-Trac](https://support.syncfusion.com/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you! |
0 commit comments