Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions SfDataGridSample/SfDataGridSample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfDataGridSample", "SfDataGridSample\SfDataGridSample.csproj", "{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions SfDataGridSample/SfDataGridSample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SfDataGridSample"
x:Class="SfDataGridSample.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
15 changes: 15 additions & 0 deletions SfDataGridSample/SfDataGridSample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace SfDataGridSample
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
}
15 changes: 15 additions & 0 deletions SfDataGridSample/SfDataGridSample/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="SfDataGridSample.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SfDataGridSample"
Shell.FlyoutBehavior="Flyout"
Title="SfDataGridSample">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions SfDataGridSample/SfDataGridSample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SfDataGridSample
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
69 changes: 69 additions & 0 deletions SfDataGridSample/SfDataGridSample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
xmlns:local="clr-namespace:SfDataGridSample"
x:Class="SfDataGridSample.MainPage">

<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>

<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="cellTemplate">
<Button Text="Test" />
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>

<Grid ColumnDefinitions="*,300"
RowDefinitions="Auto,Auto">
<syncfusion:SfDataGrid x:Name="dataGrid"
Grid.Column="0"
Grid.Row="0"
AllowGroupExpandCollapse="True"
ColumnWidthMode="Auto"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
AutoGenerateColumnsMode="None"
ItemsSource="{Binding Employees}">

<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />
<syncfusion:DataGridTemplateColumn MappingName="Name"
HeaderText="Employee Name"
CellTemplate="{StaticResource cellTemplate}" />

</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

<syncfusion:SfDataGrid x:Name="dataGrid1"
Grid.Column="0"
Grid.Row="1"
ItemsSource="{Binding Employees}">
</syncfusion:SfDataGrid>

<VerticalStackLayout Grid.Column="1">
<Grid RowDefinitions="80,80">
<Button Text="Serialize"
Grid.Row="0"
Margin="0,0,0,20"
WidthRequest="150"
Clicked="Button_Clicked" />
<Button Text="Deserialize"
Grid.Row="1"
Margin="0,20,0,0"
WidthRequest="150"
Clicked="Button_Clicked_1" />
</Grid>
</VerticalStackLayout>
</Grid>


</ContentPage>
61 changes: 61 additions & 0 deletions SfDataGridSample/SfDataGridSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Syncfusion.Maui.DataGrid;

namespace SfDataGridSample
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
this.dataGrid.SerializationController = new SerializationControllerExt(this.dataGrid, Resources);
this.dataGrid1.SerializationController = new SerializationControllerExt(this.dataGrid1, Resources);
}

private void Button_Clicked(object sender, EventArgs e)
{
string localPath = Path.Combine(FileSystem.AppDataDirectory, "DataGrid.xml");
using (var file = File.Create(localPath))
{
dataGrid.Serialize(file);
}
}

private void Button_Clicked_1(object sender, EventArgs e)
{
string localPath = Path.Combine(FileSystem.AppDataDirectory, "DataGrid.xml");

using (var file = File.Open(localPath, FileMode.Open))
{
dataGrid1.Deserialize(file);
}
}
}

public class SerializationControllerExt : DataGridSerializationController
{

private readonly ResourceDictionary _pageResources;

public SerializationControllerExt(SfDataGrid grid, ResourceDictionary pageResources)
: base(grid)
{
_pageResources = pageResources;
}

protected override void RestoreColumnProperties(SerializableDataGridColumn serializableColumn, DataGridColumn column)
{
base.RestoreColumnProperties(serializableColumn, column);

if (column is DataGridTemplateColumn templateColumn &&
string.Equals(templateColumn.MappingName, "Name", StringComparison.Ordinal))
{
if (_pageResources.TryGetValue("cellTemplate", out var template) &&
template is DataTemplate dataTemplate)
{
templateColumn.CellTemplate = dataTemplate;
}
}
}
}

}
27 changes: 27 additions & 0 deletions SfDataGridSample/SfDataGridSample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;

namespace SfDataGridSample
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
113 changes: 113 additions & 0 deletions SfDataGridSample/SfDataGridSample/Model/Employee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System.ComponentModel;

namespace SfDataGridSample
{
public class Employee : INotifyPropertyChanged
{
private int? _employeeID;
private string? _name;
private long _iDNumber;
private int _contactID;
private string? _loginID;
private int _managerID;
private string? _title;
private DateTime _birthDate;
private string? _maritalStatus;
private string? _gender;
private DateTime _hireDate;
private int _sickLeaveHours;
private double _salary;
private bool _employeeStatus;
private int _rating;
private bool _isButtonVisible;

public int? EmployeeID
{
get { return _employeeID; }
set { _employeeID = value; OnPropertyChanged(nameof(EmployeeID)); }
}
public string? Name
{
get { return _name; }
set { _name = value; OnPropertyChanged(nameof(Name)); }
}
public long IDNumber
{
get { return _iDNumber; }
set { _iDNumber = value; OnPropertyChanged(nameof(IDNumber)); }
}
public string? Title
{
get { return _title; }
set { _title = value; OnPropertyChanged(nameof(Title)); }
}
public int ContactID
{
get { return _contactID; }
set { _contactID = value; OnPropertyChanged(nameof(ContactID)); }
}
public DateTime BirthDate
{
get { return _birthDate; }
set { _birthDate = value; OnPropertyChanged(nameof(BirthDate)); }
}
public string? MaritalStatus
{
get { return _maritalStatus; }
set { _maritalStatus = value; OnPropertyChanged(nameof(MaritalStatus)); }
}
public string? Gender
{
get { return _gender; }
set { _gender = value; OnPropertyChanged(nameof(Gender)); }
}
public DateTime HireDate
{
get { return _hireDate; }
set { _hireDate = value; OnPropertyChanged(nameof(HireDate)); }
}
public int SickLeaveHours
{
get { return _sickLeaveHours; }
set { _sickLeaveHours = value; OnPropertyChanged(nameof(SickLeaveHours)); }
}
public double Salary
{
get { return _salary; }
set { _salary = value; OnPropertyChanged(nameof(Salary)); }
}
public string? LoginID
{
get { return _loginID; }
set { _loginID = value; OnPropertyChanged(nameof(LoginID)); }
}
public int ManagerID
{
get { return _managerID; }
set { _managerID = value; OnPropertyChanged(nameof(ManagerID)); }
}
public bool EmployeeStatus
{
get { return _employeeStatus; }
set { _employeeStatus = value; OnPropertyChanged(nameof(EmployeeStatus)); }
}
public int Rating
{
get { return _rating; }
set { _rating = value; OnPropertyChanged(nameof(Rating)); }
}

public bool IsButtonVisible
{
get { return _isButtonVisible; }
set { _isButtonVisible = value; OnPropertyChanged(nameof(IsButtonVisible)); }
}

public event PropertyChangedEventHandler? PropertyChanged;

protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace SfDataGridSample
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace SfDataGridSample
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Loading