Skip to content

Commit 464b2bf

Browse files
Merge pull request #8 from SyncfusionExamples/991454-GridWebAPI
991454: Connecting SQL data to Blazor DataGrid Using Web API Adaptor Sample Updated.
2 parents f1a8829 + dafcae8 commit 464b2bf

File tree

21 files changed

+565
-0
lines changed

21 files changed

+565
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.10" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.10">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
<PackageReference Include="Syncfusion.Blazor.Data" Version="31.1.17" />
16+
<PackageReference Include="Syncfusion.Blazor.Grid" Version="31.1.17" />
17+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="31.1.17" />
18+
</ItemGroup>
19+
20+
</Project>
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.35825.156 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorApp", "BlazorApp.csproj", "{BB902517-F5F0-4947-B4D8-616EB598D2A4}"
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+
{BB902517-F5F0-4947-B4D8-616EB598D2A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{BB902517-F5F0-4947-B4D8-616EB598D2A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{BB902517-F5F0-4947-B4D8-616EB598D2A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{BB902517-F5F0-4947-B4D8-616EB598D2A4}.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 = {FF4733F1-980B-457B-AB72-F8870DD589B9}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
9+
<link rel="stylesheet" href="app.css" />
10+
<link rel="stylesheet" href="BlazorApp.styles.css" />
11+
<link rel="icon" type="image/png" href="favicon.png" />
12+
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
13+
<HeadOutlet @rendermode="InteractiveServer" />
14+
</head>
15+
16+
<body>
17+
<Routes @rendermode="InteractiveServer" />
18+
<script src="_framework/blazor.web.js"></script>
19+
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
20+
</body>
21+
22+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="page">
4+
<main>
5+
<article class="content px-4">
6+
@Body
7+
</article>
8+
</main>
9+
</div>
10+
11+
<div id="blazor-error-ui">
12+
An unhandled error has occurred.
13+
<a href="" class="reload">Reload</a>
14+
<a class="dismiss">🗙</a>
15+
</div>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.page {
2+
position: relative;
3+
display: flex;
4+
flex-direction: column;
5+
}
6+
7+
main {
8+
flex: 1;
9+
}
10+
11+
.sidebar {
12+
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
13+
}
14+
15+
.top-row {
16+
background-color: #f7f7f7;
17+
border-bottom: 1px solid #d6d5d5;
18+
justify-content: flex-end;
19+
height: 3.5rem;
20+
display: flex;
21+
align-items: center;
22+
}
23+
24+
.top-row ::deep a, .top-row ::deep .btn-link {
25+
white-space: nowrap;
26+
margin-left: 1.5rem;
27+
text-decoration: none;
28+
}
29+
30+
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
31+
text-decoration: underline;
32+
}
33+
34+
.top-row ::deep a:first-child {
35+
overflow: hidden;
36+
text-overflow: ellipsis;
37+
}
38+
39+
@media (max-width: 640.98px) {
40+
.top-row {
41+
justify-content: space-between;
42+
}
43+
44+
.top-row ::deep a, .top-row ::deep .btn-link {
45+
margin-left: 0;
46+
}
47+
}
48+
49+
@media (min-width: 641px) {
50+
.page {
51+
flex-direction: row;
52+
}
53+
54+
.sidebar {
55+
width: 250px;
56+
height: 100vh;
57+
position: sticky;
58+
top: 0;
59+
}
60+
61+
.top-row {
62+
position: sticky;
63+
top: 0;
64+
z-index: 1;
65+
}
66+
67+
.top-row.auth ::deep a:first-child {
68+
flex: 1;
69+
text-align: right;
70+
width: 0;
71+
}
72+
73+
.top-row, article {
74+
padding-left: 2rem !important;
75+
padding-right: 1.5rem !important;
76+
}
77+
}
78+
79+
#blazor-error-ui {
80+
background: lightyellow;
81+
bottom: 0;
82+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
83+
display: none;
84+
left: 0;
85+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
86+
position: fixed;
87+
width: 100%;
88+
z-index: 1000;
89+
}
90+
91+
#blazor-error-ui .dismiss {
92+
cursor: pointer;
93+
position: absolute;
94+
right: 0.75rem;
95+
top: 0.5rem;
96+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@page "/"
2+
@using BlazorApp.Data
3+
4+
<SfGrid TValue="Order" Toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Cancel", "Update"})">
5+
<SfDataManager Url="api/orders" Adaptor="Adaptors.WebApiAdaptor" ></SfDataManager>
6+
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true"></GridEditSettings>
7+
<GridColumns>
8+
<GridColumn Field=@nameof(Order.OrderId) HeaderText="Order ID" IsIdentity="true" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
9+
<GridColumn Field=@nameof(Order.CustomerId) HeaderText="Customer Name" Width="150"></GridColumn>
10+
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
11+
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
12+
</GridColumns>
13+
</SfGrid>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
4+
<FocusOnNavigate RouteData="routeData" Selector="h1" />
5+
</Found>
6+
</Router>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using static Microsoft.AspNetCore.Components.Web.RenderMode
7+
@using Microsoft.AspNetCore.Components.Web.Virtualization
8+
@using Microsoft.JSInterop
9+
@using BlazorApp
10+
@using BlazorApp.Components
11+
@using Syncfusion.Blazor.Grids
12+
@using Syncfusion.Blazor
13+
@using Syncfusion.Blazor.Data
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using BlazorApp.Data;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace BlazorApp.Controllers
6+
{
7+
[Route("api/[controller]")]
8+
[ApiController]
9+
public class OrdersController : ControllerBase
10+
{
11+
private OrdersDetailsContext _context;
12+
13+
public OrdersController (OrdersDetailsContext context )
14+
{
15+
_context = context;
16+
}
17+
18+
[HttpGet]
19+
public object Get ()
20+
{
21+
return new { Items = _context.Orders, Count = _context.Orders.Count() };
22+
}
23+
24+
[HttpPost]
25+
public void Post ( [FromBody]Order newOrder )
26+
{
27+
_context.Orders.Add(newOrder);
28+
_context.SaveChanges();
29+
}
30+
31+
[HttpPut]
32+
public void Put ( [FromBody]Order updatedOrder )
33+
{
34+
Order _updatedOrder = _context.Orders.Where(x => x.OrderId.Equals(updatedOrder.OrderId)).FirstOrDefault();
35+
_updatedOrder.CustomerId = updatedOrder.CustomerId;
36+
_updatedOrder.Freight = updatedOrder.Freight;
37+
_updatedOrder.OrderDate = updatedOrder.OrderDate;
38+
_context.SaveChanges();
39+
}
40+
41+
[HttpDelete("{id}")]
42+
public void Delete(int id )
43+
{
44+
Order deletingOrder = _context.Orders.Where(x => x.OrderId.Equals(id)).FirstOrDefault();
45+
_context.Orders.Remove(deletingOrder);
46+
_context.SaveChanges();
47+
}
48+
}
49+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace BlazorApp.Data;
5+
6+
public partial class Order
7+
{
8+
public int OrderId { get; set; }
9+
10+
public string CustomerId { get; set; } = null!;
11+
12+
public DateTime? OrderDate { get; set; }
13+
14+
public double? Freight { get; set; }
15+
}

0 commit comments

Comments
 (0)