Skip to content

Commit 50fee28

Browse files
Committed sample to perform sorting
1 parent 75eaa54 commit 50fee28

40 files changed

+1198
-0
lines changed

MAUI_DataGrid_Sorting/App.xaml

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:MAUI_DataGrid_Sorting"
5+
x:Class="MAUI_DataGrid_Sorting.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>

MAUI_DataGrid_Sorting/App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace MAUI_DataGrid_Sorting;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
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+
<Shell
3+
x:Class="MAUI_DataGrid_Sorting.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:MAUI_DataGrid_Sorting"
7+
Shell.FlyoutBehavior="Disabled">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MAUI_DataGrid_Sorting;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Syncfusion.Maui.Data;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace MAUI_DataGrid_Sorting
10+
{
11+
public class CustomSortComparer : IComparer<object>, ISortDirection
12+
{
13+
private ListSortDirection sortDirection;
14+
private int nameX;
15+
private int nameY;
16+
17+
public ListSortDirection SortDirection
18+
{
19+
get { return this.sortDirection; }
20+
set { this.sortDirection = value; }
21+
}
22+
23+
public int Compare(object x, object y)
24+
{
25+
if (x!.GetType() == typeof(OrderInfo))
26+
{
27+
this.nameX = ((OrderInfo)x!).Customer.Length;
28+
this.nameY = ((OrderInfo)y!).Customer.Length;
29+
}
30+
else
31+
{
32+
this.nameX = x.ToString()!.Length;
33+
this.nameY = y!.ToString()!.Length;
34+
}
35+
if (this.nameX.CompareTo(this.nameY) > 0)
36+
{
37+
return this.SortDirection == ListSortDirection.Ascending ? 1 : -1;
38+
}
39+
else if (this.nameX.CompareTo(this.nameY) == -1)
40+
{
41+
return this.SortDirection == ListSortDirection.Ascending ? -1 : 1;
42+
}
43+
else
44+
{
45+
return 0;
46+
}
47+
}
48+
}
49+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>MAUI_DataGrid_Sorting</RootNamespace>
10+
<UseMaui>true</UseMaui>
11+
<SingleProject>true</SingleProject>
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
14+
<!-- Display name -->
15+
<ApplicationTitle>MAUI_DataGrid_Sorting</ApplicationTitle>
16+
17+
<!-- App Identifier -->
18+
<ApplicationId>com.companyname.maui_datagrid_sorting</ApplicationId>
19+
<ApplicationIdGuid>31bca77d-4f0c-45bb-be2b-a738907ac37f</ApplicationIdGuid>
20+
21+
<!-- Versions -->
22+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
23+
<ApplicationVersion>1</ApplicationVersion>
24+
25+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
26+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
27+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
28+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
29+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
30+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
31+
</PropertyGroup>
32+
33+
<ItemGroup>
34+
<!-- App Icon -->
35+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
36+
37+
<!-- Splash Screen -->
38+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
39+
40+
<!-- Images -->
41+
<MauiImage Include="Resources\Images\*" />
42+
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
43+
44+
<!-- Custom Fonts -->
45+
<MauiFont Include="Resources\Fonts\*" />
46+
47+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
48+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
49+
</ItemGroup>
50+
51+
<ItemGroup>
52+
<PackageReference Include="Syncfusion.Maui.DataGrid" Version="20.4.38" />
53+
</ItemGroup>
54+
55+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5+
<ActiveDebugFramework>net6.0-android</ActiveDebugFramework>
6+
<ActiveDebugProfile>Pixel 5 - API 32 (Android 12.1 - API 32)</ActiveDebugProfile>
7+
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
8+
<DefaultDevice>pixel_5_-_api_32</DefaultDevice>
9+
</PropertyGroup>
10+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAUI_DataGrid_Sorting", "MAUI_DataGrid_Sorting.csproj", "{8F02B176-DC23-4C94-B664-0E7510292DDA}"
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+
{8F02B176-DC23-4C94-B664-0E7510292DDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8F02B176-DC23-4C94-B664-0E7510292DDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8F02B176-DC23-4C94-B664-0E7510292DDA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{8F02B176-DC23-4C94-B664-0E7510292DDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{8F02B176-DC23-4C94-B664-0E7510292DDA}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{8F02B176-DC23-4C94-B664-0E7510292DDA}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
26+
EndGlobalSection
27+
EndGlobal
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
5+
xmlns:data="clr-namespace:Syncfusion.Maui.Data;assembly=Syncfusion.Maui.Data"
6+
xmlns:local="clr-namespace:MAUI_DataGrid_Sorting"
7+
x:Class="MAUI_DataGrid_Sorting.MainPage">
8+
9+
<ContentPage.BindingContext>
10+
<local:OrderInfoRepo />
11+
</ContentPage.BindingContext>
12+
13+
<ContentPage.Resources>
14+
<local:CustomSortComparer x:Key="comparer" />
15+
</ContentPage.Resources>
16+
17+
<ContentPage.Content>
18+
19+
<syncfusion:SfDataGrid ItemsSource="{Binding Orders}"
20+
AutoGenerateColumnsMode="None"
21+
GridLinesVisibility="Both"
22+
HeaderGridLinesVisibility="Both"
23+
ColumnWidthMode="FitByHeader"
24+
SortingMode="Multiple"
25+
AllowTriStateSorting="True"
26+
ShowSortNumbers="True"
27+
SortingGestureType="Tap">
28+
29+
<syncfusion:SfDataGrid.Columns>
30+
<syncfusion:DataGridTextColumn MappingName="OrderID"
31+
HeaderText="Order ID"></syncfusion:DataGridTextColumn>
32+
<syncfusion:DataGridTextColumn MappingName="CustomerID"
33+
HeaderText="Customer ID"
34+
AllowSorting="True"></syncfusion:DataGridTextColumn>
35+
<syncfusion:DataGridTextColumn MappingName="Customer"
36+
HeaderText="Name"></syncfusion:DataGridTextColumn>
37+
<syncfusion:DataGridTextColumn MappingName="ShipCountry"
38+
HeaderText="Country"></syncfusion:DataGridTextColumn>
39+
</syncfusion:SfDataGrid.Columns>
40+
41+
<!--Sort columns by custom logic-->
42+
<!--
43+
<syncfusion:SfDataGrid.SortComparers>
44+
<data:SortComparer Comparer="{StaticResource comparer}" PropertyName="Customer" />
45+
</syncfusion:SfDataGrid.SortComparers>-->
46+
47+
<syncfusion:SfDataGrid.SortColumnDescriptions>
48+
<syncfusion:SortColumnDescription ColumnName="CustomerID" SortDirection="Ascending"/>
49+
</syncfusion:SfDataGrid.SortColumnDescriptions>
50+
51+
</syncfusion:SfDataGrid>
52+
</ContentPage.Content>
53+
54+
</ContentPage>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace MAUI_DataGrid_Sorting;
2+
3+
public partial class MainPage : ContentPage
4+
{
5+
int count = 0;
6+
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+

0 commit comments

Comments
 (0)