Skip to content

Commit fa7ca83

Browse files
dimodiDimo Dimovmarin-bratanov
authored
Migrate Grid DataSourceRequest on Server examples to v3.0 (#157)
* Migrate Grid DataSourceRequest on Server examples to v3.0 * chore(grid): revert to 3.1 wasm server ref Co-authored-by: Dimo Dimov <dimo@Dimos-MacBook-Pro.local> Co-authored-by: Marin Bratanov <m.bratanov@gmail.com>
1 parent be5865d commit fa7ca83

File tree

18 files changed

+35
-61
lines changed

18 files changed

+35
-61
lines changed

grid/datasourcerequest-on-server/CustomSerializer/Client/CustomSerializer.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
1111
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
1212
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
13-
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.20.0" />
13+
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.0.1" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<ProjectReference Include="..\Shared\CustomSerializer.Shared.csproj" />

grid/datasourcerequest-on-server/CustomSerializer/Client/Pages/Index.razor

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<TelerikGrid Height="550px" FilterMode="@GridFilterMode.FilterMenu"
99
Sortable="true" Pageable="true" PageSize="20" Groupable="true"
10-
Data=@GridData TotalCount=@Total OnRead=@ReadItems>
10+
TItem="@WeatherForecast" OnRead="@ReadItems">
1111
<GridColumns>
1212
<GridColumn Field="Id" FieldType="@(typeof(int))" Title="Id" Width="100px" Groupable="false" />
1313
<GridColumn Field="Date" FieldType="@(typeof(DateTime))">
@@ -22,10 +22,7 @@
2222
</TelerikGrid>
2323

2424
@code {
25-
List<object> GridData { get; set; }
26-
public int Total { get; set; } = 0;
27-
28-
protected async Task ReadItems(GridReadEventArgs args)
25+
async Task ReadItems(GridReadEventArgs args)
2926
{
3027
// we pass the request to the service, and there Telerik DataSource Extension methods will shape the data
3128
// then the service returns our project-specific envelope so that the data can be serialized by the framework
@@ -35,16 +32,14 @@
3532
if (args.Request.Groups.Count > 0)
3633
{
3734
var data = GroupDataHelpers.DeserializeGroups<WeatherForecast>(result.GroupedData);
38-
GridData = data.Cast<object>().ToList();
35+
args.Data = data.Cast<object>().ToList();
3936
}
4037
else
4138
{
42-
GridData = result.CurrentPageData.Cast<object>().ToList();
39+
args.Data = result.CurrentPageData.Cast<object>().ToList();
4340
}
4441

45-
Total = result.TotalItemCount;
46-
47-
StateHasChanged();
42+
args.Total = result.TotalItemCount;
4843
}
4944

5045
// for brevity, CUD operations are not implemented, only Read

grid/datasourcerequest-on-server/CustomSerializer/Client/Services/WeatherForecastService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using Microsoft.AspNetCore.Components;
2-
using Newtonsoft.Json;
32
using System;
43
using System.Collections.Generic;
54
using System.Linq;
65
using System.Net.Http;
76
using System.Net.Http.Json;
87
using System.Threading.Tasks;
98
using Telerik.DataSource;
10-
using Newtonsoft.Json.Serialization;
119
using System.Text.Json;
1210
using CustomSerializer.Shared;
1311

grid/datasourcerequest-on-server/CustomSerializer/Client/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<base href="/" />
88
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
99
<link href="css/site.css" rel="stylesheet" />
10-
<link rel="stylesheet" href="https://unpkg.com/@progress/kendo-theme-default@latest/dist/all.css" />
1110

11+
<link rel="stylesheet" href="_content/Telerik.UI.for.Blazor/css/kendo-theme-default/all.css" />
1212
<script src="_content/Telerik.UI.for.Blazor/js/telerik-blazor.js" defer></script>
1313
</head>
1414
<body>

grid/datasourcerequest-on-server/CustomSerializer/Server/Controllers/WeatherForecastController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
using Microsoft.Extensions.Logging;
88
using Telerik.DataSource;
99
using Telerik.DataSource.Extensions;
10-
using Newtonsoft.Json;
11-
using Newtonsoft.Json.Serialization;
1210

1311
namespace CustomSerializer.Server.Controllers
1412
{

grid/datasourcerequest-on-server/CustomSerializer/Server/CustomSerializer.Server.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<PropertyGroup Condition=" '$(RunConfiguration)' == 'ClientHosted.Server' " />
78
<ItemGroup>
89
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.1" />
910
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5" />
11+
<PackageReference Include="Telerik.DataSource" Version="2.1.1" />
1012
</ItemGroup>
1113

1214
<ItemGroup>

grid/datasourcerequest-on-server/CustomSerializer/Shared/CustomSerializer.Shared.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
9-
<PackageReference Include="Telerik.DataSource" Version="2.0.7" />
8+
<PackageReference Include="Telerik.DataSource" Version="2.1.1" />
109
</ItemGroup>
1110

1211
</Project>

grid/datasourcerequest-on-server/ServerApp/Pages/Index.razor

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<TelerikGrid Height="550px" FilterMode="@GridFilterMode.FilterMenu"
88
Sortable="true" Pageable="true" Groupable="true" PageSize="20"
9-
Data=@GridData TotalCount=@Total OnRead=@ReadItems>
9+
TItem="@WeatherForecast" OnRead="@ReadItems">
1010
<GridColumns>
1111
<GridColumn Field="Id" FieldType="@(typeof(int))" Title="Id" Width="100px" Groupable="false" />
1212
<GridColumn Field="Date" FieldType="@(typeof(DateTime))">
@@ -21,20 +21,14 @@
2121
</TelerikGrid>
2222

2323
@code {
24-
List<object> GridData { get; set; }
25-
public int Total { get; set; } = 0;
26-
2724
protected async Task ReadItems(GridReadEventArgs args)
2825
{
2926
// we pass the request to the service, and there Telerik DataSource Extension methods will shape the data
3027
var datasourceResult = await ForecastService.GetForecastListAsync(args.Request);
3128

32-
GridData = datasourceResult.Data.Cast<object>().ToList();
33-
34-
Total = datasourceResult.Total;
35-
36-
StateHasChanged();
29+
args.Data = datasourceResult.Data.Cast<object>().ToList();
30+
args.Total = datasourceResult.Total;
3731
}
3832

3933
// for brevity, CUD operations are not implemented, only Read
40-
}
34+
}

grid/datasourcerequest-on-server/ServerApp/ServerApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.16.0" />
8+
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.0.1" />
99
</ItemGroup>
1010

1111
</Project>

grid/datasourcerequest-on-server/WasmApp/Client/Pages/Index.razor

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<TelerikGrid Height="550px" FilterMode="@GridFilterMode.FilterMenu"
88
Sortable="true" Pageable="true" Groupable="true" PageSize="20"
9-
Data=@GridData TotalCount=@Total OnRead=@ReadItems>
9+
TItem="@WeatherForecast" OnRead="@ReadItems">
1010
<GridColumns>
1111
<GridColumn Field="Id" FieldType="@(typeof(int))" Title="Id" Width="100px" Groupable="false" />
1212
<GridColumn Field="Date" FieldType="@(typeof(DateTime))">
@@ -21,31 +21,24 @@
2121
</TelerikGrid>
2222

2323
@code {
24-
List<object> GridData { get; set; }
25-
public int Total { get; set; } = 0;
26-
27-
protected async Task ReadItems(GridReadEventArgs args)
24+
async Task ReadItems(GridReadEventArgs args)
2825
{
2926
// we pass the request to the service, and there Telerik DataSource Extension methods will shape the data
3027
// then the service returns our project-specific envelope so that the data can be serialized by the framework
3128
DataEnvelope<WeatherForecast> result = await ForecastService.GetForecastListAsync(args.Request);
3229

33-
3430
if (args.Request.Groups.Count > 0)
3531
{
3632
var data = GroupDataHelpers.DeserializeGroups<WeatherForecast>(result.GroupedData);
37-
GridData = data.Cast<object>().ToList();
33+
args.Data = data.Cast<object>().ToList();
3834
}
3935
else
4036
{
41-
GridData = result.CurrentPageData.Cast<object>().ToList();
37+
args.Data = result.CurrentPageData.Cast<object>().ToList();
4238
}
4339

44-
Total = result.TotalItemCount;
45-
46-
StateHasChanged();
40+
args.Total = result.TotalItemCount;
4741
}
4842

49-
5043
// for brevity, CUD operations are not implemented, only Read
51-
}
44+
}

grid/datasourcerequest-on-server/WasmApp/Client/WasmApp.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" />
1111
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" />
1212
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
13-
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.20.0" />
13+
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.0.1" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<ProjectReference Include="..\Shared\WasmApp.Shared.csproj" />

grid/datasourcerequest-on-server/WasmApp/Server/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3434

3535
app.UseStaticFiles();
3636
app.UseBlazorFrameworkFiles();
37-
3837
app.UseRouting();
3938

4039
app.UseEndpoints(endpoints =>

grid/datasourcerequest-on-server/WasmApp/Server/WasmApp.Server.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<PropertyGroup Condition=" '$(RunConfiguration)' == 'ClientApp.Server' " />
78
<ItemGroup>
89
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.1" />
9-
<PackageReference Include="Telerik.DataSource" Version="2.0.7" />
10+
<PackageReference Include="Telerik.DataSource" Version="2.1.1" />
1011
</ItemGroup>
1112

1213
<ItemGroup>
1314
<ProjectReference Include="..\Client\WasmApp.Client.csproj" />
1415
<ProjectReference Include="..\Shared\WasmApp.Shared.csproj" />
1516
</ItemGroup>
16-
1717
</Project>

grid/datasourcerequest-on-server/WasmApp/Shared/WasmApp.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
9-
<PackageReference Include="Telerik.DataSource" Version="2.0.7" />
9+
<PackageReference Include="Telerik.DataSource" Version="2.1.1" />
1010
</ItemGroup>
1111

1212
</Project>

grid/datasourcerequest-on-server/WebApiFromServerApp/SampleWebApi/SampleWebApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Telerik.DataSource" Version="2.0.4" />
8+
<PackageReference Include="Telerik.DataSource" Version="2.1.1" />
99
</ItemGroup>
1010

1111
<ItemGroup>

grid/datasourcerequest-on-server/WebApiFromServerApp/SharedClasses/SharedClasses.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Telerik.DataSource" Version="2.0.4" />
8+
<PackageReference Include="Telerik.DataSource" Version="2.1.1" />
99
</ItemGroup>
1010

1111
</Project>

grid/datasourcerequest-on-server/WebApiFromServerApp/WebApiFromServerApp/Pages/GridWithService.razor

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
<h3>URL to POST to: @ActionUrl</h3>
66

7-
<TelerikGrid Data=@GridData TotalCount=@Total OnRead=@ReadItems Groupable="true"
8-
FilterMode=@GridFilterMode.FilterMenu Sortable=true Pageable=true Height="300px">
7+
<TelerikGrid TItem="@WeatherForecast" OnRead="@ReadItems" Groupable="true"
8+
FilterMode="@GridFilterMode.FilterMenu" Sortable="true" Pageable="true" Height="300px">
99
<GridColumns>
1010
<GridColumn Field="Id" FieldType="@(typeof(int))" Title="Id" Width="100px" Groupable="false" />
1111
<GridColumn Field="Date" FieldType="@(typeof(DateTime))">
@@ -21,10 +21,8 @@
2121

2222
@code {
2323
[Parameter] public string ActionUrl { get; set; }
24-
public List<object> GridData { get; set; }
25-
public int Total { get; set; } = 0;
2624

27-
protected async Task ReadItems(GridReadEventArgs args)
25+
async Task ReadItems(GridReadEventArgs args)
2826
{
2927
// we pass the request to the service, and there Telerik DataSource Extension methods will shape the data
3028
// then the service returns our project-specific envelope so that the data can be serialized by the framework
@@ -33,15 +31,13 @@
3331
if (args.Request.Groups.Count > 0)
3432
{
3533
var data = GroupDataHelpers.DeserializeGroups<WeatherForecast>(result.GroupedData);
36-
GridData = data.Cast<object>().ToList();
34+
args.Data = data.Cast<object>().ToList();
3735
}
3836
else
3937
{
40-
GridData = result.CurrentPageData.Cast<object>().ToList();
38+
args.Data = result.CurrentPageData.Cast<object>().ToList();
4139
}
4240

43-
Total = result.TotalItemCount;
44-
45-
StateHasChanged();
41+
args.Total = result.TotalItemCount;
4642
}
47-
}
43+
}

grid/datasourcerequest-on-server/WebApiFromServerApp/WebApiFromServerApp/WebApiFromServerApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.16.0" />
8+
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.0.1" />
99
</ItemGroup>
1010

1111
<ItemGroup>

0 commit comments

Comments
 (0)