Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 6dc63aa

Browse files
Merge branch 'dev' into master
2 parents c115aec + 98c94aa commit 6dc63aa

28 files changed

+1068
-151
lines changed

src/BlazorTable.Sample.Shared/BlazorTable.Sample.Shared.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.10" />
10-
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.10" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.11" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.11" />
1111
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
1212
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
1313
</ItemGroup>

src/BlazorTable.Sample.Shared/NavMenu.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
<span class="oi oi-home" aria-hidden="true"></span> Dynamic Columns
6868
</NavLink>
6969
</li>
70+
<li class="nav-item px-3">
71+
<NavLink class="nav-link" href="ServerSideData" Match="NavLinkMatch.All">
72+
<span class="oi oi-home" aria-hidden="true"></span> Server side data
73+
</NavLink>
74+
</li>
7075
<li class="nav-item px-3">
7176
<NavLink class="nav-link" href="ToggleColumnVisibility" Match="NavLinkMatch.All">
7277
<span class="oi oi-eye" aria-hidden="true"></span> Column Visibility
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
@page "/ServerSideData"
2+
@inject HttpClient Http
3+
@using BlazorTable
4+
@using BlazorTable.Interfaces
5+
@using BlazorTable.Components.ServerSide
6+
7+
<h1>Server side data</h1>
8+
9+
<Table TableItem="PersonData" DataLoader="_loader" Items="data" PageSize="15" ShowSearchBar="true">
10+
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Width="10%" DefaultSortColumn="true" />
11+
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Width="20%" />
12+
<Column TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Width="20%">
13+
<Template>
14+
<a href="mailto:@context.email">@context.email</a>
15+
</Template>
16+
</Column>
17+
<Column TableItem="PersonData" Title="Paid" Field="@(x => x.paid)" Sortable="true" Width="10%">
18+
<Template>
19+
@context.paid.ToString()
20+
</Template>
21+
</Column>
22+
<Column TableItem="PersonData" Title="Price" Field="@(x => x.price)" Sortable="true" Width="10%" Format="C" Align="Align.Right" />
23+
<Column TableItem="PersonData" Title="Created Date" Field="@(x => x.created_date)" Sortable="true" Width="10%">
24+
<Template>
25+
@(context.created_date.HasValue ? context.created_date.Value.ToShortDateString() : string.Empty)
26+
</Template>
27+
</Column>
28+
<Pager ShowPageNumber="true" ShowTotalCount="true" />
29+
</Table>
30+
31+
@code
32+
{
33+
[Inject]
34+
private HttpClient httpClient { get; set; }
35+
36+
public class PersonData
37+
{
38+
public int? id { get; set; }
39+
public string full_name { get; set; }
40+
public string email { get; set; }
41+
public bool? paid { get; set; }
42+
public decimal? price { get; set; }
43+
public DateTime? created_date { get; set; }
44+
}
45+
46+
private IDataLoader<PersonData> _loader;
47+
48+
private IEnumerable<PersonData> data;
49+
50+
protected override async Task OnInitializedAsync()
51+
{
52+
_loader = new PersonDataLoader(httpClient);
53+
data = (await _loader.LoadDataAsync(null)).Records;
54+
}
55+
56+
public class PersonDataLoader : IDataLoader<PersonData>
57+
{
58+
private readonly HttpClient _client;
59+
public PersonDataLoader(HttpClient client)
60+
{
61+
_client = client;
62+
}
63+
public async Task<PaginationResult<PersonData>> LoadDataAsync(FilterData parameters)
64+
{
65+
66+
var data = await _client.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
67+
IQueryable<PersonData> query = data.AsQueryable();
68+
if (parameters?.Query != null)
69+
{
70+
query = query.Where(
71+
x => x.email.ToLowerInvariant().Contains(parameters.Query.ToLowerInvariant()) ||
72+
x.full_name.ToLowerInvariant().Contains(parameters.Query.ToLowerInvariant()));
73+
}
74+
if (parameters?.OrderBy != null)
75+
{
76+
var orderBy = parameters.OrderBy.Split(" ");
77+
if (orderBy.Length == 2)
78+
{
79+
var isSortDescending = orderBy[1] == "desc";
80+
var prop = typeof(PersonData).GetProperty(orderBy[0]);
81+
query = isSortDescending ? query.OrderByDescending(x => prop.GetValue(x, null))
82+
: query.OrderBy(x => prop.GetValue(x, null));
83+
}
84+
}
85+
var results = parameters?.Top.HasValue ?? false ?
86+
query.Skip(parameters.Skip.GetValueOrDefault())
87+
.Take(parameters.Top.Value).ToArray() :
88+
query.ToArray();
89+
90+
return new PaginationResult<PersonData>
91+
{
92+
Records = results,
93+
Skip = parameters?.Skip ?? 0,
94+
Total = query.ToList().Count,
95+
Top = parameters?.Top ?? 0
96+
};
97+
}
98+
}
99+
100+
}

src/BlazorTable.Tests/BlazorTable.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
1111
<PackageReference Include="PuppeteerSharp" Version="2.0.4" />
1212
<PackageReference Include="PuppeteerSharp.Contrib.Extensions" Version="3.0.0" />
13-
<PackageReference Include="Shouldly" Version="4.0.1" />
13+
<PackageReference Include="Shouldly" Version="4.0.3" />
1414
<PackageReference Include="xunit" Version="2.4.1" />
1515
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
19-
<PackageReference Include="coverlet.collector" Version="1.3.0">
19+
<PackageReference Include="coverlet.collector" Version="3.0.2">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>

src/BlazorTable/BlazorTable.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="LINQKit.Core" Version="1.1.21" />
31-
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.10" />
32-
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.10" />
33-
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.10" />
34-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
30+
<PackageReference Include="LINQKit.Core" Version="1.1.22" />
31+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.11" />
32+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.11" />
33+
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.11" />
34+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.2">
3535
<PrivateAssets>all</PrivateAssets>
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3737
</PackageReference>
@@ -45,15 +45,15 @@
4545
</ItemGroup>
4646

4747
<ItemGroup>
48-
<Compile Update="Components\Localization.Designer.cs">
48+
<Compile Update="Localization\Localization.Designer.cs">
4949
<DesignTime>True</DesignTime>
5050
<AutoGen>True</AutoGen>
5151
<DependentUpon>Localization.resx</DependentUpon>
5252
</Compile>
5353
</ItemGroup>
5454

5555
<ItemGroup>
56-
<EmbeddedResource Update="Components\Localization.resx">
56+
<EmbeddedResource Update="Localization\Localization.resx">
5757
<Generator>ResXFileCodeGenerator</Generator>
5858
<LastGenOutput>Localization.Designer.cs</LastGenOutput>
5959
</EmbeddedResource>

src/BlazorTable/Components/Column.razor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Globalization;
44
using System.Linq;
55
using System.Linq.Expressions;
6+
using System.Threading.Tasks;
67

78
namespace BlazorTable
89
{
@@ -225,7 +226,7 @@ public void ToggleFilter()
225226
/// <summary>
226227
/// Sort by this column
227228
/// </summary>
228-
public void SortBy()
229+
public async Task SortByAsync()
229230
{
230231
if (Sortable)
231232
{
@@ -238,7 +239,7 @@ public void SortBy()
238239

239240
SortColumn = true;
240241

241-
Table.Update();
242+
await Table.UpdateAsync().ConfigureAwait(false);
242243
}
243244
}
244245

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@namespace BlazorTable
22
@typeparam TableItem
3-
@inject Microsoft.Extensions.Localization.IStringLocalizer<BlazorTable.Components.Localization> Localization
43

54
<CascadingValue Value="(IColumn<TableItem>)this.Column" Name="Column">
65
@ChildContent
@@ -9,6 +8,6 @@
98

109
<div class="justify-content-md-center">
1110
<button type="button" class="btn btn-danger btn-xs" role="button" @onclick="@((x) => Column.ToggleFilter())">@Localization["FilterManagerClose"]</button>
12-
<button type="button" class="btn btn-secondary btn-xs" role="button" @onclick="@((x) => ClearFilter())">@Localization["FilterManagerClear"]</button>
13-
<button type="button" class="btn btn-primary btn-xs" role="button" @onclick="@((x) => ApplyFilter())">@Localization["FilterManagerApply"]</button>
11+
<button type="button" class="btn btn-secondary btn-xs" role="button" @onclick="@(async (x) => await ClearFilterAsync())">@Localization["FilterManagerClear"]</button>
12+
<button type="button" class="btn btn-primary btn-xs" role="button" @onclick="@(async (x) => await ApplyFilterAsync())">@Localization["FilterManagerApply"]</button>
1413
</div>

src/BlazorTable/Components/FilterManager.razor.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.AspNetCore.Components;
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Components;
3+
using Microsoft.Extensions.Localization;
24
using Microsoft.Extensions.Logging;
35

46
namespace BlazorTable
@@ -14,30 +16,34 @@ public partial class FilterManager<TableItem>
1416
[Inject]
1517
public ILogger<FilterManager<TableItem>> Logger { get; set; }
1618

17-
private void ApplyFilter()
19+
[Inject]
20+
IStringLocalizer<Localization.Localization> Localization { get; set; }
21+
22+
private async Task ApplyFilterAsync()
23+
1824
{
1925
Column.ToggleFilter();
2026

2127
if (Column.FilterControl != null)
2228
{
2329
Column.Filter = Column.FilterControl.GetFilter();
24-
Column.Table.Update();
25-
Column.Table.FirstPage();
30+
await Column.Table.UpdateAsync().ConfigureAwait(false);
31+
await Column.Table.FirstPageAsync().ConfigureAwait(false);
2632
}
2733
else
2834
{
2935
Logger.LogInformation("Filter is null");
3036
}
3137
}
3238

33-
private void ClearFilter()
39+
private async Task ClearFilterAsync()
3440
{
3541
Column.ToggleFilter();
3642

3743
if (Column.Filter != null)
3844
{
3945
Column.Filter = null;
40-
Column.Table.Update();
46+
await Column.Table.UpdateAsync().ConfigureAwait(false);
4147
}
4248
}
4349
}

src/BlazorTable/Components/Pager.razor

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@namespace BlazorTable
2-
@inject Microsoft.Extensions.Localization.IStringLocalizer<BlazorTable.Components.Localization> Localization
32

43
@if (AlwaysShow || (Table.TotalPages > 1))
54
{
@@ -8,7 +7,7 @@
87
@if (ShowPageSizes)
98
{
109
<li class="page-item" title="Set Page Size">
11-
<select class="form-control" value="@Table.PageSize" @onchange="SetPageSize">
10+
<select class="form-control" value="@Table.PageSize" @onchange="(async ev => await SetPageSizeAsync(ev))">
1211
@foreach (int option in PageSizes)
1312
{
1413
<option value="@option">@option</option>
@@ -18,13 +17,13 @@
1817
}
1918
@if (ShowPageNumber)
2019
{
21-
<li class="page-item disabled" @onclick="@(() => Table.FirstPage())" title="Page @(Table.PageNumber + 1)/@(Table.TotalPages)">
20+
<li class="page-item disabled" @onclick="@(() => Table.FirstPageAsync())" title="Page @(Table.PageNumber + 1)/@(Table.TotalPages)">
2221
<a class="page-link" href="#" tabindex="-1" aria-disabled="true">@(Table.PageNumber + 1)/@(Table.TotalPages)</a>
2322
</li>
2423
}
2524
@if (ShowTotalCount)
2625
{
27-
<li class="page-item disabled" @onclick="@(() => Table.FirstPage())" title="Total Items @Table.TotalCount">
26+
<li class="page-item disabled" @onclick="@(() => Table.FirstPageAsync())" title="Total Items @Table.TotalCount">
2827
<a class="page-link" href="#" tabindex="-1" aria-disabled="true">@Table.TotalCount</a>
2928
</li>
3029
}
@@ -35,16 +34,16 @@
3534
</li>
3635
}
3736

38-
<li class="page-item @(Table.PageNumber == 0 ? "disabled": "")" @onclick="@(() => Table.FirstPage())" title="@Localization["PagerFirst"]">
37+
<li class="page-item @(Table.PageNumber == 0 ? "disabled": "")" @onclick="@(() => Table.FirstPageAsync())" title="@Localization["PagerFirst"]">
3938
<a class="page-link" href="javascript:;" aria-disabled="@(Table.PageNumber == 0 ? "true": null)">@Localization["PagerFirst"]</a>
4039
</li>
41-
<li class="page-item @(Table.PageNumber == 0 ? "disabled": "")" @onclick="@(() => Table.PreviousPage())" title="@Localization["PagerPrevious"]">
40+
<li class="page-item @(Table.PageNumber == 0 ? "disabled": "")" @onclick="@(() => Table.PreviousPageAsync())" title="@Localization["PagerPrevious"]">
4241
<a class="page-link" href="javascript:;" aria-disabled="@(Table.PageNumber == 0 ? "true": null)">@Localization["PagerPrevious"]</a>
4342
</li>
44-
<li class="page-item @(Table.PageNumber + 1 < Table.TotalPages ? "" : "disabled")" @onclick="@(() => Table.NextPage())" title="@Localization["PagerNext"]">
43+
<li class="page-item @(Table.PageNumber + 1 < Table.TotalPages ? "" : "disabled")" @onclick="@(() => Table.NextPageAsync())" title="@Localization["PagerNext"]">
4544
<a class="page-link" href="javascript:;" aria-disabled="@(Table.PageNumber + 1 < Table.TotalPages ? null: "true")">@Localization["PagerNext"]</a>
4645
</li>
47-
<li class="page-item @(Table.PageNumber + 1 != Table.TotalPages ? "" : "disabled")" @onclick="@(() => Table.LastPage())" title="@Localization["PagerLast"]">
46+
<li class="page-item @(Table.PageNumber + 1 != Table.TotalPages ? "" : "disabled")" @onclick="@(() => Table.LastPageAsync())" title="@Localization["PagerLast"]">
4847
<a class="page-link" href="javascript:;" aria-disabled="@(Table.PageNumber + 1 != Table.TotalPages ? null : "true")">@Localization["PagerLast"]</a>
4948
</li>
5049
</ul>

src/BlazorTable/Components/Pager.razor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Components;
2+
using Microsoft.Extensions.Localization;
23
using System.Collections.Generic;
3-
using System.Threading;
4+
using System.Threading.Tasks;
45

56
namespace BlazorTable
67
{
@@ -42,11 +43,14 @@ public partial class Pager
4243
[Parameter]
4344
public bool ShowPageSizes { get; set; }
4445

45-
private void SetPageSize(ChangeEventArgs args)
46+
[Inject]
47+
IStringLocalizer<Localization.Localization> Localization { get; set; }
48+
49+
private async Task SetPageSizeAsync(ChangeEventArgs args)
4650
{
4751
if (int.TryParse(args.Value.ToString(), out int result))
4852
{
49-
Table.SetPageSize(result);
53+
await Table.SetPageSizeAsync(result).ConfigureAwait(false);
5054
}
5155
}
5256
}

0 commit comments

Comments
 (0)