This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from IvanJosipovic/dev
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
Showing
36 changed files
with
1,376 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
100
src/BlazorTable.Sample.Shared/Pages/ServerSideData.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.