Skip to content

Commit f196e23

Browse files
author
Joseph Herson Thomas
committed
Add blazor web assembly adaptive ui sample
1 parent 8470dfa commit f196e23

30 files changed

+1375
-0
lines changed
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.4.33205.214
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grid-Adaptive Layout", "Grid-Adaptive Layout\Grid-Adaptive Layout.csproj", "{6BCB23B5-9B54-4548-8DAE-9F15451AA6A1}"
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+
{6BCB23B5-9B54-4548-8DAE-9F15451AA6A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6BCB23B5-9B54-4548-8DAE-9F15451AA6A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6BCB23B5-9B54-4548-8DAE-9F15451AA6A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6BCB23B5-9B54-4548-8DAE-9F15451AA6A1}.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 = {28F24DD9-B3B3-4CE5-92E4-2E951436069E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.11" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.11" PrivateAssets="all" />
12+
<PackageReference Include="Syncfusion.Blazor.Grid" Version="20.4.0.52" />
13+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="20.4.0.52" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@page "/adaptiveui-using-mediaquery"
2+
3+
@using Syncfusion.Blazor
4+
@using Syncfusion.Blazor.Grids
5+
6+
<p>DataGrid Adaptive UI layout using Media Query Component</p>
7+
8+
<div style="position:relative; min-height: 500px;">
9+
<SfMediaQuery @bind-ActiveBreakPoint="activeBreakpoint" />
10+
@if (activeBreakpoint == "Small")
11+
{
12+
rowDirection = RowDirection.Vertical;
13+
}
14+
else
15+
{
16+
rowDirection = RowDirection.Horizontal;
17+
}
18+
<SfGrid DataSource="@Orders" AllowSorting="true" AllowFiltering="true"
19+
EnableAdaptiveUI="true" AdaptiveUIMode="AdaptiveMode.Mobile" RowRenderingMode="@rowDirection"
20+
Height="100%" Width="100%" AllowPaging="true"
21+
Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update", "Search" })">
22+
<GridFilterSettings Type="@FilterType.Excel" />
23+
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog" />
24+
<GridColumns>
25+
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" Width="80" ValidationRules="@(new ValidationRules{ Required= true })" />
26+
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120" />
27+
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" Width="130" />
28+
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="120" />
29+
</GridColumns>
30+
</SfGrid>
31+
</div>
32+
33+
@code {
34+
public List<Order>? Orders { get; set; }
35+
private string? activeBreakpoint { get; set; }
36+
private RowDirection rowDirection { get; set; }
37+
38+
protected override void OnInitialized()
39+
{
40+
Orders = Enumerable.Range(1, 75).Select(x => new Order()
41+
{
42+
OrderID = 1000 + x,
43+
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
44+
Freight = 2.1 * x,
45+
OrderDate = DateTime.Now.AddDays(-x),
46+
}).ToList();
47+
}
48+
49+
public class Order
50+
{
51+
public int? OrderID { get; set; }
52+
public string? CustomerID { get; set; }
53+
public DateTime? OrderDate { get; set; }
54+
public double? Freight { get; set; }
55+
}
56+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@page "/fetchdata"
2+
@inject HttpClient Http
3+
4+
<PageTitle>Weather forecast</PageTitle>
5+
6+
<h1>Weather forecast</h1>
7+
8+
<p>This component demonstrates fetching data from the server.</p>
9+
10+
@if (forecasts == null)
11+
{
12+
<p><em>Loading...</em></p>
13+
}
14+
else
15+
{
16+
<table class="table">
17+
<thead>
18+
<tr>
19+
<th>Date</th>
20+
<th>Temp. (C)</th>
21+
<th>Temp. (F)</th>
22+
<th>Summary</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
@foreach (var forecast in forecasts)
27+
{
28+
<tr>
29+
<td>@forecast.Date.ToShortDateString()</td>
30+
<td>@forecast.TemperatureC</td>
31+
<td>@forecast.TemperatureF</td>
32+
<td>@forecast.Summary</td>
33+
</tr>
34+
}
35+
</tbody>
36+
</table>
37+
}
38+
39+
@code {
40+
private WeatherForecast[]? forecasts;
41+
42+
protected override async Task OnInitializedAsync()
43+
{
44+
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
45+
}
46+
47+
public class WeatherForecast
48+
{
49+
public DateTime Date { get; set; }
50+
51+
public int TemperatureC { get; set; }
52+
53+
public string? Summary { get; set; }
54+
55+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
56+
}
57+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@page "/"
2+
3+
@using Syncfusion.Blazor.Grids
4+
5+
<p>DataGrid Adaptive UI demo</p>
6+
7+
<div style="position:relative; min-height: 500px;">
8+
<SfGrid DataSource="@Orders" AllowSorting="true" AllowFiltering="true" EnableAdaptiveUI="true"
9+
AdaptiveUIMode="AdaptiveMode.Mobile" Height="100%" Width="100%" AllowPaging="true"
10+
Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update", "Search" })">
11+
<GridFilterSettings Type="@FilterType.Excel" />
12+
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog" />
13+
<GridColumns>
14+
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" Width="80" />
15+
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120" />
16+
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" Width="130" />
17+
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="120" />
18+
</GridColumns>
19+
</SfGrid>
20+
</div>
21+
22+
@code {
23+
public List<Order>? Orders { get; set; }
24+
25+
protected override void OnInitialized()
26+
{
27+
Orders = Enumerable.Range(1, 75).Select(x => new Order()
28+
{
29+
OrderID = 1000 + x,
30+
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
31+
Freight = 2.1 * x,
32+
OrderDate = DateTime.Now.AddDays(-x),
33+
}).ToList();
34+
}
35+
36+
public class Order
37+
{
38+
public int? OrderID { get; set; }
39+
public string? CustomerID { get; set; }
40+
public DateTime? OrderDate { get; set; }
41+
public double? Freight { get; set; }
42+
}
43+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Grid_Adaptive_Layout;
2+
using Microsoft.AspNetCore.Components.Web;
3+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
4+
using Syncfusion.Blazor;
5+
6+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
7+
builder.RootComponents.Add<App>("#app");
8+
builder.RootComponents.Add<HeadOutlet>("head::after");
9+
10+
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
11+
12+
builder.Services.AddSyncfusionBlazor();
13+
await builder.Build().RunAsync();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:33284",
7+
"sslPort": 44382
8+
}
9+
},
10+
"profiles": {
11+
"Grid-Adaptive Layout": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
16+
"applicationUrl": "https://localhost:7030;http://localhost:5275",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"IIS Express": {
22+
"commandName": "IISExpress",
23+
"launchBrowser": true,
24+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
}
29+
}
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="page">
4+
<div class="sidebar">
5+
<NavMenu />
6+
</div>
7+
8+
<main>
9+
<div class="top-row px-4">
10+
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
11+
</div>
12+
13+
<article class="content px-4">
14+
@Body
15+
</article>
16+
</main>
17+
</div>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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:not(.auth) {
41+
display: none;
42+
}
43+
44+
.top-row.auth {
45+
justify-content: space-between;
46+
}
47+
48+
.top-row ::deep a, .top-row ::deep .btn-link {
49+
margin-left: 0;
50+
}
51+
}
52+
53+
@media (min-width: 641px) {
54+
.page {
55+
flex-direction: row;
56+
}
57+
58+
.sidebar {
59+
width: 250px;
60+
height: 100vh;
61+
position: sticky;
62+
top: 0;
63+
}
64+
65+
.top-row {
66+
position: sticky;
67+
top: 0;
68+
z-index: 1;
69+
}
70+
71+
.top-row.auth ::deep a:first-child {
72+
flex: 1;
73+
text-align: right;
74+
width: 0;
75+
}
76+
77+
.top-row, article {
78+
padding-left: 2rem !important;
79+
padding-right: 1.5rem !important;
80+
}
81+
}

0 commit comments

Comments
 (0)