Skip to content

Commit 7e0a880

Browse files
Merge pull request #1 from SyncfusionExamples/MAUI-Clear-Sorting-Grouping
MAUI - 965938 - Added KB sample to reset sorting and grouping programmatically
2 parents 4f7d918 + 1a12c77 commit 7e0a880

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9502
-2
lines changed

README.md

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,102 @@
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!
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35806.99 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfDataGridSample", "SfDataGridSample\SfDataGridSample.csproj", "{91580AE4-A7AF-4595-BAA5-B0293B881891}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{91580AE4-A7AF-4595-BAA5-B0293B881891}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{91580AE4-A7AF-4595-BAA5-B0293B881891}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{91580AE4-A7AF-4595-BAA5-B0293B881891}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{91580AE4-A7AF-4595-BAA5-B0293B881891}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1DB1A789-AD6D-4BE4-9EFF-CDFDE50CC39D}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:SfDataGridSample"
5+
x:Class="SfDataGridSample.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace SfDataGridSample
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="SfDataGridSample.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:SfDataGridSample"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="SfDataGridSample">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace SfDataGridSample
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="SfDataGridSample.MainPage"
5+
xmlns:local="clr-namespace:SfDataGridSample.ViewModel"
6+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid">
7+
8+
<ContentPage.BindingContext>
9+
<local:ViewModel />
10+
</ContentPage.BindingContext>
11+
<Grid ColumnDefinitions="*,200" ColumnSpacing="5" Padding="10">
12+
<VerticalStackLayout HorizontalOptions="Center" Grid.Column="1" VerticalOptions="Center" Spacing="10">
13+
<Button Text="Allow Sorting"
14+
Clicked="Button_Clicked"
15+
WidthRequest="150"/>
16+
<Button Text="Clear Sorting"
17+
Clicked="Button_Clicked_1"
18+
WidthRequest="150"/>
19+
<Button Text="Allow Grouping"
20+
Clicked="Button_Clicked_2"
21+
WidthRequest="150"/>
22+
<Button Text="Clear Grouping"
23+
Clicked="Button_Clicked_3"
24+
WidthRequest="150"/>
25+
</VerticalStackLayout>
26+
<syncfusion:SfDataGrid x:Name="datagrid"
27+
Grid.Column="0"
28+
ColumnWidthMode="Fill"
29+
ItemsSource="{Binding OrderList}">
30+
<syncfusion:SfDataGrid.Columns>
31+
<syncfusion:DataGridNumericColumn MappingName="OrderID" HeaderText="Order ID"/>
32+
<syncfusion:DataGridTextColumn MappingName="CustomerID" HeaderText="Customer ID"/>
33+
<syncfusion:DataGridDateColumn MappingName="ShippingDate" HeaderText="Order Date"/>
34+
<syncfusion:DataGridNumericColumn MappingName="SupplierID" HeaderText="Supplier ID"/>
35+
<syncfusion:DataGridTextColumn MappingName="ShipCity" HeaderText="Shipping City"/>
36+
<syncfusion:DataGridTextColumn MappingName="ShipCountry" HeaderText="Shipping Country"/>
37+
<syncfusion:DataGridNumericColumn MappingName="Freight" HeaderText="Freight"/>
38+
</syncfusion:SfDataGrid.Columns>
39+
</syncfusion:SfDataGrid>
40+
</Grid>
41+
</ContentPage>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Syncfusion.Maui.DataGrid;
2+
3+
namespace SfDataGridSample
4+
{
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
private void Button_Clicked(object sender, EventArgs e)
13+
{
14+
datagrid.SortingMode = Syncfusion.Maui.DataGrid.DataGridSortingMode.Multiple;
15+
}
16+
17+
private void Button_Clicked_1(object sender, EventArgs e)
18+
{
19+
datagrid.SortColumnDescriptions.Clear();
20+
}
21+
22+
private void Button_Clicked_2(object sender, EventArgs e)
23+
{
24+
datagrid.GroupingMode = Syncfusion.Maui.DataGrid.GroupingMode.Multiple;
25+
datagrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
26+
{
27+
ColumnName = "ShipCountry",
28+
});
29+
datagrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
30+
{
31+
ColumnName = "ShipCity",
32+
});
33+
}
34+
35+
private void Button_Clicked_3(object sender, EventArgs e)
36+
{
37+
datagrid.GroupColumnDescriptions.Clear();
38+
}
39+
}
40+
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace SfDataGridSample;
5+
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}

0 commit comments

Comments
 (0)