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

Commit

Permalink
Merge pull request #251 from IvanJosipovic/dev
Browse files Browse the repository at this point in the history
New Features
- Server side data loading! (thanks @nadais)
- Toggle detail template programmatically (thanks @NilsPur)
- Custom Row (thanks @NilsPur)
- Add property ShowChildContentAtTop (thanks @obie73)

Additional Localization
- Danish (thanks @KBBA)
- Spanish (thanks @ekuhlmann23)
- Brasilian Portuguese (thanks @carlos-sergio-carvalho)
  • Loading branch information
IvanJosipovic authored Feb 1, 2021
2 parents 269d58e + b9ce343 commit 54d8667
Show file tree
Hide file tree
Showing 36 changed files with 1,376 additions and 200 deletions.
1 change: 1 addition & 0 deletions src/BlazorTable.Sample.Server/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ app {

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
overflow: auto;
}

.sidebar .top-row {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.10" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.11" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/BlazorTable.Sample.Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,21 @@
<span class="oi oi-home" aria-hidden="true"></span> Dynamic Columns
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="ServerSideData" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Server side data
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="ToggleColumnVisibility" Match="NavLinkMatch.All">
<span class="oi oi-eye" aria-hidden="true"></span> Column Visibility
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="CustomRow" Match="NavLinkMatch.All">
<span class="oi oi-align-center" aria-hidden="true"></span> Custom Row
</NavLink>
</li>
</ul>
</div>

Expand Down
42 changes: 41 additions & 1 deletion src/BlazorTable.Sample.Shared/Pages/Detail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,28 @@

<p>The <code>DetailTemplate</code> can be used to display additional details below an item.</p>
<br />
<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true">
<div class="btn-toolbar mb-3">
<div class="btn-group mr-2">
<button class="btn btn-primary" @onclick="_ => Try(() => table.ToggleAllDetailsView(open: true))">Open All</button>
<button class="btn btn-danger" @onclick="_ => Try(() => table.ToggleAllDetailsView(open: false))">Close All</button>
</div>
<div class="input-group mr-1">
<div class="input-group-prepend">
<div class="input-group-text">Row Number:</div>
</div>
<input type="number" @bind="rowNumber" class="form-control">
</div>
<div class="btn-group">
<button class="btn btn-primary" @onclick="_ => Try(() => table.ToggleDetailView(rowNumber, open: true))">Open</button>
<button class="btn btn-danger" @onclick="_ => Try(() => table.ToggleDetailView(rowNumber, open: false))">Close</button>
</div>
</div>
<br />
@if (errorMessage != "")
{
<label>@errorMessage</label>
}
<Table @ref="table" TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<Column TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Filterable="true" Width="20%">
Expand Down Expand Up @@ -46,8 +67,14 @@
[Inject]
private HttpClient Http { get; set; }

private ITable<PersonData> table;

private PersonData[] data;

private int rowNumber;

private string errorMessage = "";

protected override async Task OnInitializedAsync()
{
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
Expand All @@ -71,4 +98,17 @@
MasterCard = 1,
Visa = 2
}

private void Try(Action action)
{
try
{
errorMessage = "";
action();
}
catch (Exception e)
{
errorMessage = e.Message;
}
}
}
80 changes: 80 additions & 0 deletions src/BlazorTable.Sample.Shared/Pages/RowTemplate.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@page "/CustomRow"
@inject HttpClient Http
@using BlazorTable
@using System.ComponentModel

<h1>Row Template - Custom Row</h1>

<p></p>

<p>Use</p>

<Table @ref="table" TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" ShowSearchBar="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<Column TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Filterable="true" Width="20%">
<Template>
<a href="mailto:@context.email">@context.email</a>
</Template>
</Column>
<Column TableItem="PersonData" Title="Paid" Field="@(x => x.paid)" Sortable="true" Filterable="true" Width="10%">
<Template>
@context.paid.ToString()
</Template>
</Column>
<Column TableItem="PersonData" Title="Price" Field="@(x => x.price)" Sortable="true" Filterable="true" Width="10%" Format="C" Align="Align.Right" />
<Column TableItem="PersonData" Title="Created Date" Field="@(x => x.created_date)" Sortable="true" Filterable="true" Width="10%">
<Template>
@(context.created_date.HasValue ? context.created_date.Value.ToShortDateString() : string.Empty)
</Template>
</Column>
<Column TableItem="PersonData" Title="Enum" Field="@(x => x.cc_type)" Sortable="true" Filterable="true" Width="10%">
<Template>
@context.cc_type
</Template>
</Column>
<CustomRow TableItem="PersonData" IsActiveForItem="x => (x.id % 4) == 0">
<tr>
<td colspan="@(table.Columns.Count)">
<div class="text-center w-100"><b>Custom Row</b></div>
</td>
</tr>
</CustomRow>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
{
[Inject]
private HttpClient httpClient { get; set; }

private ITable<PersonData> table;

private PersonData[] data;

private int i = 0;

protected override async Task OnInitializedAsync()
{
data = await httpClient.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
{
public int? id { get; set; }
public string full_name { get; set; }
public string email { get; set; }
public bool? paid { get; set; }
public decimal? price { get; set; }
public CreditCard? cc_type { get; set; }
public DateTime? created_date { get; set; }
}

public enum CreditCard
{
none = 0,
[Description("MasterCard")]
MasterCard = 1,
Visa = 2
}
}
100 changes: 100 additions & 0 deletions src/BlazorTable.Sample.Shared/Pages/ServerSideData.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
@page "/ServerSideData"
@inject HttpClient Http
@using BlazorTable
@using BlazorTable.Interfaces
@using BlazorTable.Components.ServerSide

<h1>Server side data</h1>

<Table TableItem="PersonData" DataLoader="_loader" Items="data" PageSize="15" ShowSearchBar="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Width="20%" />
<Column TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Width="20%">
<Template>
<a href="mailto:@context.email">@context.email</a>
</Template>
</Column>
<Column TableItem="PersonData" Title="Paid" Field="@(x => x.paid)" Sortable="true" Width="10%">
<Template>
@context.paid.ToString()
</Template>
</Column>
<Column TableItem="PersonData" Title="Price" Field="@(x => x.price)" Sortable="true" Width="10%" Format="C" Align="Align.Right" />
<Column TableItem="PersonData" Title="Created Date" Field="@(x => x.created_date)" Sortable="true" Width="10%">
<Template>
@(context.created_date.HasValue ? context.created_date.Value.ToShortDateString() : string.Empty)
</Template>
</Column>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
{
[Inject]
private HttpClient httpClient { get; set; }

public class PersonData
{
public int? id { get; set; }
public string full_name { get; set; }
public string email { get; set; }
public bool? paid { get; set; }
public decimal? price { get; set; }
public DateTime? created_date { get; set; }
}

private IDataLoader<PersonData> _loader;

private IEnumerable<PersonData> data;

protected override async Task OnInitializedAsync()
{
_loader = new PersonDataLoader(httpClient);
data = (await _loader.LoadDataAsync(null)).Records;
}

public class PersonDataLoader : IDataLoader<PersonData>
{
private readonly HttpClient _client;
public PersonDataLoader(HttpClient client)
{
_client = client;
}
public async Task<PaginationResult<PersonData>> LoadDataAsync(FilterData parameters)
{

var data = await _client.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
IQueryable<PersonData> query = data.AsQueryable();
if (parameters?.Query != null)
{
query = query.Where(
x => x.email.ToLowerInvariant().Contains(parameters.Query.ToLowerInvariant()) ||
x.full_name.ToLowerInvariant().Contains(parameters.Query.ToLowerInvariant()));
}
if (parameters?.OrderBy != null)
{
var orderBy = parameters.OrderBy.Split(" ");
if (orderBy.Length == 2)
{
var isSortDescending = orderBy[1] == "desc";
var prop = typeof(PersonData).GetProperty(orderBy[0]);
query = isSortDescending ? query.OrderByDescending(x => prop.GetValue(x, null))
: query.OrderBy(x => prop.GetValue(x, null));
}
}
var results = parameters?.Top.HasValue ?? false ?
query.Skip(parameters.Skip.GetValueOrDefault())
.Take(parameters.Top.Value).ToArray() :
query.ToArray();

return new PaginationResult<PersonData>
{
Records = results,
Skip = parameters?.Skip ?? 0,
Total = query.ToList().Count,
Top = parameters?.Top ?? 0
};
}
}

}
15 changes: 13 additions & 2 deletions src/BlazorTable.Sample.Shared/Pages/ToggleColumnVisibility.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

<h1>Toggle Column Visibility</h1>

<p>Users can change the visibility of a column if its "Hideable" attribute is set to true.</p>

<button class="btn btn-primary mb-2" @onclick="@(_ => showSearchBar = !showSearchBar)">Toggle Search Bar</button>

<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" ShowSearchBar="showSearchBar">
<Table @ref="table" TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" ShowSearchBar="showSearchBar">
<Column Hideable="true" TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column Hideable="true" TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<Column Hideable="true" TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Filterable="true" Width="20%">
Expand Down Expand Up @@ -35,17 +37,26 @@
</Table>

@code
{
{
[Inject]
private HttpClient httpClient { get; set; }

private ITable<PersonData> table;

private PersonData[] data;

private bool showSearchBar;

protected override async Task OnInitializedAsync()
{
data = await httpClient.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");

Random random = new Random(123);

foreach (IColumn<PersonData> column in table.Columns)
{
column.Visible = random.Next(2) == 1 ? true : false; // column visibility
}
}

public class PersonData
Expand Down
1 change: 1 addition & 0 deletions src/BlazorTable.Sample.Wasm/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ app {

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
overflow: auto;
}

.sidebar .top-row {
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorTable.Tests/BlazorTable.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="PuppeteerSharp" Version="2.0.4" />
<PackageReference Include="PuppeteerSharp.Contrib.Extensions" Version="3.0.0" />
<PackageReference Include="Shouldly" Version="4.0.1" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 7 additions & 7 deletions src/BlazorTable/BlazorTable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="LINQKit.Core" Version="1.1.21" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.10" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
<PackageReference Include="LINQKit.Core" Version="1.1.22" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.11" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.11" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -45,15 +45,15 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Components\Localization.Designer.cs">
<Compile Update="Localization\Localization.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Localization.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Components\Localization.resx">
<EmbeddedResource Update="Localization\Localization.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Localization.Designer.cs</LastGenOutput>
</EmbeddedResource>
Expand Down
Loading

0 comments on commit 54d8667

Please sign in to comment.