Skip to content

Commit 8e08948

Browse files
authored
Committed the example project.
1 parent 6c34d85 commit 8e08948

29 files changed

+1370
-2
lines changed

App.razor

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>

MyBlazorProject.csproj

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.2.0-preview1.20073.1" />
10+
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
12+
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
13+
<PackageReference Include="Syncfusion.Blazor" Version="18.1.0.56" />
14+
</ItemGroup>
15+
16+
</Project>

MyBlazorProject.csproj.user

+6
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>IIS Express</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>

MyBlazorProject.sln

+25
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 16
4+
VisualStudioVersion = 16.0.29424.173
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyBlazorProject", "MyBlazorProject.csproj", "{97D0F337-BC9D-4D96-AFDB-2A86BB7DE9C8}"
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+
{97D0F337-BC9D-4D96-AFDB-2A86BB7DE9C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{97D0F337-BC9D-4D96-AFDB-2A86BB7DE9C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{97D0F337-BC9D-4D96-AFDB-2A86BB7DE9C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{97D0F337-BC9D-4D96-AFDB-2A86BB7DE9C8}.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 = {20F99420-39E9-43BE-A318-0B2FACE40579}
24+
EndGlobalSection
25+
EndGlobal

Pages/Counter.razor

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/counter"
2+
3+
<h1>Counter</h1>
4+
5+
<p>Current count: @currentCount</p>
6+
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
8+
9+
@code {
10+
private int currentCount = 0;
11+
12+
private void IncrementCount()
13+
{
14+
currentCount++;
15+
}
16+
}

Pages/FetchData.razor

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@page "/fetchdata"
2+
@inject HttpClient Http
3+
4+
<h1>Weather forecast</h1>
5+
6+
<p>This component demonstrates fetching data from the server.</p>
7+
8+
@if (forecasts == null)
9+
{
10+
<p><em>Loading...</em></p>
11+
}
12+
else
13+
{
14+
<table class="table">
15+
<thead>
16+
<tr>
17+
<th>Date</th>
18+
<th>Temp. (C)</th>
19+
<th>Temp. (F)</th>
20+
<th>Summary</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
@foreach (var forecast in forecasts)
25+
{
26+
<tr>
27+
<td>@forecast.Date.ToShortDateString()</td>
28+
<td>@forecast.TemperatureC</td>
29+
<td>@forecast.TemperatureF</td>
30+
<td>@forecast.Summary</td>
31+
</tr>
32+
}
33+
</tbody>
34+
</table>
35+
}
36+
37+
@code {
38+
private WeatherForecast[] forecasts;
39+
40+
protected override async Task OnInitializedAsync()
41+
{
42+
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
43+
}
44+
45+
public class WeatherForecast
46+
{
47+
public DateTime Date { get; set; }
48+
49+
public int TemperatureC { get; set; }
50+
51+
public string Summary { get; set; }
52+
53+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
54+
}
55+
}

Pages/Index.razor

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
@page "/"
2+
@using System.Dynamic;
3+
4+
<SfGrid DataSource="@Orders">
5+
<GridColumns>
6+
<GridColumn Field="OrderID"
7+
HeaderText="Order ID"
8+
TextAlign="TextAlign.Right"
9+
Width="120">
10+
</GridColumn>
11+
<GridColumn Field="CustomerID"
12+
HeaderText="Customer Name"
13+
Width="150">
14+
</GridColumn>
15+
<GridColumn Field="OrderDate"
16+
HeaderText=" Order Date"
17+
EditType="EditType.DatePickerEdit"
18+
TextAlign="TextAlign.Right"
19+
Format="d"
20+
Type="ColumnType.Date"
21+
Width="130">
22+
</GridColumn>
23+
<GridColumn Field="Freight"
24+
HeaderText="Freight"
25+
Format="C2"
26+
TextAlign="TextAlign.Right"
27+
Width="120">
28+
</GridColumn>
29+
</GridColumns>
30+
</SfGrid>
31+
32+
@code{
33+
public List<OrderDetails> Orders { get; set; } = new List<OrderDetails>();
34+
35+
protected override void OnInitialized()
36+
{
37+
Orders = Enumerable.Range(1, 12).Select((x) =>
38+
{
39+
dynamic dynamicObj = new OrderDetails();
40+
dynamicObj.OrderID = 1000 + x;
41+
dynamicObj.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })
42+
[new Random().Next(5)];
43+
dynamicObj.Freight = 2.1 * x;
44+
dynamicObj.OrderDate = DateTime.Now.AddDays(-x);
45+
return dynamicObj;
46+
}).Cast<OrderDetails>().ToList<OrderDetails>();
47+
}
48+
49+
public class OrderDetails : DynamicObject
50+
{
51+
Dictionary<string, object> OrdersDictionary = new Dictionary<string, object>();
52+
53+
public override bool TryGetMember(GetMemberBinder binder, out object result)
54+
{
55+
string name = binder.Name;
56+
return OrdersDictionary.TryGetValue(name, out result);
57+
}
58+
59+
public override bool TrySetMember(SetMemberBinder binder, object value)
60+
{
61+
OrdersDictionary[binder.Name] = value;
62+
return true;
63+
}
64+
65+
public override IEnumerable<string> GetDynamicMemberNames()
66+
{
67+
return this.OrdersDictionary?.Keys;
68+
}
69+
70+
//Expando Object Binding
71+
//public List<ExpandoObject> Orders { get; set; } = new List<ExpandoObject>();
72+
73+
//protected override void OnInitialized()
74+
//{
75+
// Orders = Enumerable.Range(1, 12).Select((x) =>
76+
// {
77+
// dynamic dynamicObj = new ExpandoObject();
78+
// dynamicObj.OrderID = 1000 + x;
79+
// dynamicObj.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })
80+
// [new Random().Next(5)];
81+
// dynamicObj.Freight = 2.1 * x;
82+
// dynamicObj.OrderDate = DateTime.Now.AddDays(-x);
83+
// return dynamicObj;
84+
// }).Cast<ExpandoObject>().ToList<ExpandoObject>();
85+
//}
86+
}
87+
}
88+

Program.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using System.Text;
5+
using Microsoft.AspNetCore.Blazor.Hosting;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Syncfusion.Blazor;
8+
9+
namespace MyBlazorProject
10+
{
11+
public class Program
12+
{
13+
public static async Task Main(string[] args)
14+
{
15+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Add your licence");
16+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
17+
builder.RootComponents.Add<App>("app");
18+
builder.Services.AddSyncfusionBlazor();
19+
await builder.Build().RunAsync();
20+
}
21+
}
22+
}

Properties/launchSettings.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:49681/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"MyBlazorProject": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:49682/"
25+
}
26+
}
27+
}

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
# -binding-expando-and-dynamic-objects-to-a-blazor-data-grid
2-
A quick start Blazor WebAssembly app that helps you to bind the Expando and Dynamic Objects to a Blazor Data Grid.
1+
# Binding Expando and Dynamic objects to a Blazor Data Grid
2+
A quick start Blazor WebAssembly app that helps you to bind the Expando and Dynamic Objects to a Blazor Data Grid.
3+
4+
Documentation:
5+
https://blazor.syncfusion.com/documentation/datagrid/data-binding/#expandoobject-binding
6+
https://blazor.syncfusion.com/documentation/datagrid/data-binding/#dynamicobject-binding
7+
8+
Online examples: https://blazor.syncfusion.com/demos/datagrid/expandoobject
9+
10+
## Project prerequisites
11+
12+
Make sure that you have the compatible versions of Visual Studio 2019 and .NET Core SDK 3.1.3 in your machine before starting to work on this project.
13+
14+
## How to run this application?
15+
16+
To run this application, you need to first clone the `binding-expando-and-dynamic-objects-to-a-blazor-data-grid` repository and then open it in Visual Studio 2019. Now, simply build and run your project to view the output.

Shared/MainLayout.razor

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>

Shared/NavMenu.razor

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">MyBlazorProject</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="oi oi-plus" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
<li class="nav-item px-3">
21+
<NavLink class="nav-link" href="fetchdata">
22+
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
23+
</NavLink>
24+
</li>
25+
</ul>
26+
</div>
27+
28+
@code {
29+
private bool collapseNavMenu = true;
30+
31+
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
32+
33+
private void ToggleNavMenu()
34+
{
35+
collapseNavMenu = !collapseNavMenu;
36+
}
37+
}

Shared/SurveyPrompt.razor

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="alert alert-secondary mt-4" role="alert">
2+
<span class="oi oi-pencil mr-2" aria-hidden="true"></span>
3+
<strong>@Title</strong>
4+
5+
<span class="text-nowrap">
6+
Please take our
7+
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2116045">brief survey</a>
8+
</span>
9+
and tell us what you think.
10+
</div>
11+
12+
@code {
13+
// Demonstrates how a parent component can supply parameters
14+
[Parameter]
15+
public string Title { get; set; }
16+
}

_Imports.razor

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@using System.Net.Http
2+
@using Microsoft.AspNetCore.Components.Forms
3+
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
5+
@using Microsoft.JSInterop
6+
@using MyBlazorProject
7+
@using MyBlazorProject.Shared
8+
@using Syncfusion.Blazor.Grids

wwwroot/SampleImg.PNG

356 KB
Loading

wwwroot/css/bootstrap/bootstrap.min.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wwwroot/css/bootstrap/bootstrap.min.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)