Skip to content

Commit 1e6b697

Browse files
ASP.NET Core Data Grid binding sample
ASP.NET Core Data Grid binding sample
1 parent eea729e commit 1e6b697

File tree

79 files changed

+74544
-2
lines changed

Some content is hidden

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

79 files changed

+74544
-2
lines changed

DataGrid.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<NoWarn>1701;1702;</NoWarn>
11+
</PropertyGroup>
12+
13+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
14+
<NoWarn>1701;1702;</NoWarn>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="23.1.43" />
19+
</ItemGroup>
20+
21+
</Project>

DataGrid.csproj.user

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>

DataGrid.sln

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.6.33717.318
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataGrid", "DataGrid.csproj", "{04F3CBC2-96ED-4D59-9BCE-E36B83397DE3}"
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+
{04F3CBC2-96ED-4D59-9BCE-E36B83397DE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{04F3CBC2-96ED-4D59-9BCE-E36B83397DE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{04F3CBC2-96ED-4D59-9BCE-E36B83397DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{04F3CBC2-96ED-4D59-9BCE-E36B83397DE3}.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 = {F4DA1DB5-98EB-44CA-A1B6-1C6A1C9C7083}
24+
EndGlobalSection
25+
EndGlobal

Pages/Error.cshtml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>

Pages/Error.cshtml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace DataGrid.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
}

Pages/Index.cshtml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
//var order = OrderDetails.GetAllRecords();
6+
}
7+
8+
<ejs-grid id="Grid" dataSource="@IndexModel.DynamicOrders" allowPaging="true">
9+
<e-grid-pagesettings pageSize="8"></e-grid-pagesettings>
10+
<e-grid-columns>
11+
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
12+
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
13+
<e-grid-column field="OrderDate" headerText=" Order Date" format="yMd" width="130"></e-grid-column>
14+
<e-grid-column field="Freight" headerText="Freight" format="C2" width="120"></e-grid-column>
15+
<e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
16+
</e-grid-columns>
17+
</ejs-grid>
18+

Pages/Index.cshtml.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Dynamic;
4+
namespace DataGrid.Pages
5+
{
6+
//public class OrderDetails
7+
//{
8+
// public static List<OrderDetails> order = new List<OrderDetails>();
9+
10+
// public OrderDetails(int OrderID, string CustomerId, int EmployeeId, double Freight,
11+
// DateTime OrderDate, string ShipCity)
12+
// {
13+
// this.OrderID = OrderID;
14+
// this.CustomerID = CustomerId;
15+
// this.EmployeeID = EmployeeId;
16+
// this.Freight = Freight;
17+
// this.ShipCity = ShipCity;
18+
// this.OrderDate = OrderDate;
19+
// }
20+
21+
// public static List<OrderDetails> GetAllRecords()
22+
// {
23+
// if (order.Count() == 0)
24+
// {
25+
// int code = 100;
26+
// for (int i = 1; i < 10; i++)
27+
// {
28+
// order.Add(new OrderDetails(code + 1, "ALFKI", i + 0, 2.3 * i, new DateTime(1991, 05, 15), "Berlin"));
29+
// order.Add(new OrderDetails(code + 2, "ANATR", i + 2, 3.3 * i, new DateTime(1990, 04, 04), "Madrid"));
30+
// order.Add(new OrderDetails(code + 3, "ANTON", i + 1, 4.3 * i, new DateTime(1957, 11, 30), "Cholchester"));
31+
// order.Add(new OrderDetails(code + 4, "BLONP", i + 3, 5.3 * i, new DateTime(1930, 10, 22), "Marseille"));
32+
// order.Add(new OrderDetails(code + 5, "BOLID", i + 4, 6.3 * i, new DateTime(1953, 02, 18), "Tsawassen"));
33+
// order.Add(new OrderDetails(code + 6, "Vinoth", i + 4, 6.3 * i, new DateTime(1953, 02, 18), "Berlin"));
34+
// code += 5;
35+
// }
36+
// }
37+
// return order;
38+
// }
39+
40+
// public int OrderID { get; set; }
41+
// public string CustomerID { get; set; }
42+
// public int? EmployeeID { get; set; }
43+
// public double? Freight { get; set; }
44+
// public string ShipCity { get; set; }
45+
// public DateTime OrderDate { get; set; }
46+
47+
//}
48+
public class DynamicDictionary : DynamicObject
49+
{
50+
public Dictionary<string, object> OrderDictionary { get; set; } = new Dictionary<string, object>();
51+
52+
public override bool TryGetMember(GetMemberBinder binder, out object? result)
53+
{
54+
string name = binder.Name;
55+
return OrderDictionary.TryGetValue(name, out result);
56+
}
57+
58+
public override bool TrySetMember(SetMemberBinder binder, object value)
59+
{
60+
OrderDictionary[binder.Name] = value;
61+
return true;
62+
}
63+
64+
public override IEnumerable<string> GetDynamicMemberNames()
65+
{
66+
return OrderDictionary.Keys;
67+
}
68+
}
69+
public class IndexModel : PageModel
70+
{
71+
public static List<DynamicDictionary>DynamicOrders { get; set; } = new List<DynamicDictionary>();
72+
public void OnGet()
73+
{
74+
DynamicOrders = Enumerable.Range(1, 10).Select((x) =>
75+
{
76+
dynamic dynamicObj = new DynamicDictionary();
77+
dynamicObj.OrderID = 1000 + x;
78+
dynamicObj.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID", "Thomp" })[new Random().Next(5)];
79+
dynamicObj.Freight = (new double[] { 2, 1, 4, 5, 3 })[new Random().Next(5)] * x;
80+
dynamicObj.OrderDate = (new DateTime[] { new DateTime(2010, 11, 5), new DateTime(2018, 10, 3), new DateTime(1995, 9, 9), new DateTime(2012, 8, 2), new DateTime(2015, 4, 11) })[new Random().Next(5)];
81+
dynamicObj.ShipCity = (new string[] { "Berlin", "Madrid", "Cholchester", "Marseille", "Tsawassen", "Berlin" })[new Random().Next(5)];
82+
return dynamicObj;
83+
}).Cast<DynamicDictionary>().ToList<DynamicDictionary>();
84+
}
85+
}
86+
}

Pages/Privacy.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>

Pages/Privacy.cshtml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace DataGrid.Pages
5+
{
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}
19+
}

Pages/Shared/_Layout.cshtml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - DataGrid</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/DataGrid.styles.css" asp-append-version="true" />
10+
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/23.1.36/fluent.css" />
11+
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js"></script>
12+
</head>
13+
<body>
14+
<header>
15+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
16+
<div class="container">
17+
<a class="navbar-brand" asp-area="" asp-page="/Index">DataGrid</a>
18+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
19+
aria-expanded="false" aria-label="Toggle navigation">
20+
<span class="navbar-toggler-icon"></span>
21+
</button>
22+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
23+
<ul class="navbar-nav flex-grow-1">
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
26+
</li>
27+
<li class="nav-item">
28+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
29+
</li>
30+
</ul>
31+
</div>
32+
</div>
33+
</nav>
34+
</header>
35+
<div class="container">
36+
<main role="main" class="pb-3">
37+
@RenderBody()
38+
</main>
39+
</div>
40+
41+
<footer class="border-top footer text-muted">
42+
<div class="container">
43+
&copy; 2023 - DataGrid - <a asp-area="" asp-page="/Privacy">Privacy</a>
44+
</div>
45+
</footer>
46+
47+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
48+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
49+
<script src="~/js/site.js" asp-append-version="true"></script>
50+
51+
@await RenderSectionAsync("Scripts", required: false)
52+
<ejs-scripts></ejs-scripts>
53+
</body>
54+
</html>

0 commit comments

Comments
 (0)