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

Commit

Permalink
Update 1.4.0
Browse files Browse the repository at this point in the history
Breaking Change: DetailTemplate/EmptyDataTemplate/LoadingDataTemplate no longer need nested Template component
Exposed Filtered Items
Added Custom Select IFilter
Fixed custom IFilters not rendering
  • Loading branch information
IvanJosipovic authored Mar 9, 2020
2 parents 47d3cfe + bdc56c7 commit 7102ac1
Show file tree
Hide file tree
Showing 28 changed files with 325 additions and 79 deletions.
7 changes: 4 additions & 3 deletions src/BlazorTable.Sample.Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"BlazorTable.Sample.Server": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:51075/",
"launchUrl": "/CustomSelect",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "http://localhost:51075/"
}
}
}
}
5 changes: 5 additions & 0 deletions src/BlazorTable.Sample.Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<span class="oi oi-home" aria-hidden="true"></span> JObject
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="/CustomSelect" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> CustomSelect
</NavLink>
</li>
</ul>
</div>

Expand Down
53 changes: 53 additions & 0 deletions src/BlazorTable.Sample.Shared/Pages/CustomSelectExample.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@page "/CustomSelect"

@using BlazorTable

<h1>CustomSelect</h1>

<p>The <code>CustomSelect</code> can be used to display custom filter options.</p>
<br />
<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true">
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%">
<CustomIFilters>
<CustomSelect TableItem="PersonData">
<CustomSelectOption Key="Astrix Mariette" Value="@("Astrix Mariette")" />
<CustomSelectOption Key="Marja Mustill" Value="@("Marja Mustill")" />
<CustomSelectOption Key="Creighton Keyzman" Value="@("Creighton Keyzman")" />
<CustomSelectOption Key="Jacobo Linton" Value="@("Jacobo Linton")" />
<CustomSelectOption Key="Michael O'Dyvoy" Value="@("Michael O'Dyvoy")" />
</CustomSelect>
</CustomIFilters>
</Column>
</Table>
@code
{
[Inject]
private HttpClient Http { get; set; }
private PersonData[] data;
protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<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
}
}
14 changes: 6 additions & 8 deletions src/BlazorTable.Sample.Shared/Pages/Detail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
</Template>
</Column>
<DetailTemplate TableItem="PersonData">
<Template Context="personContext">
<strong>Name</strong> @personContext.full_name
<br />
<strong>Email</strong> @personContext.email
<br />
<strong>Created Date</strong>@personContext.created_date
<br />
</Template>
<strong>Name</strong> @context.full_name
<br />
<strong>Email</strong> @context.email
<br />
<strong>Created Date</strong>@context.created_date
<br />
</DetailTemplate>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
Expand Down
8 changes: 3 additions & 5 deletions src/BlazorTable.Sample.Shared/Pages/EmptyData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
<Column TableItem="SampleData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="SampleData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<EmptyDataTemplate>
<Template>
<div class="text-center">
No rows found!
</div>
</Template>
<div class="text-center">
No rows found!
</div>
</EmptyDataTemplate>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
Expand Down
56 changes: 27 additions & 29 deletions src/BlazorTable.Sample.Shared/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,33 @@
@context.cc_type
</Template>
</Column>
<DetailTemplate TableItem="PersonData">
<Template Context="personContext">
<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" TableRowClass="@(x => x.RowClass)" style="background-color: white;">
<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>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
</Template>
<DetailTemplate TableItem="PersonData" Context="context2">
<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" TableRowClass="@(x => x.RowClass)" style="background-color: white;">
<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>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
</DetailTemplate>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
Expand Down
8 changes: 3 additions & 5 deletions src/BlazorTable.Sample.Shared/Pages/LoadingData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
<Column TableItem="SampleData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="SampleData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<LoadingDataTemplate>
<Template>
<div class="text-center">
<h1>Custom Loading Template</h1>
</div>
</Template>
<div class="text-center">
<h1>Custom Loading Template</h1>
</div>
</LoadingDataTemplate>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
Expand Down
1 change: 1 addition & 0 deletions src/BlazorTable.Sample.Wasm/wwwroot/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/Column.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<EnumFilter TableItem="TableItem" />
@if (this.CustomIFilters != null)
{
this.CustomIFilters(this);
@this.CustomIFilters(this);
}
</FilterManager>

Expand Down
1 change: 1 addition & 0 deletions src/BlazorTable/Components/CustomSelectOption.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@namespace BlazorTable
30 changes: 30 additions & 0 deletions src/BlazorTable/Components/CustomSelectOption.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Components;

namespace BlazorTable
{
/// <summary>
/// Option for CustomSelect
/// </summary>
public partial class CustomSelectOption
{
/// <summary>
/// Parent table
/// </summary>
[CascadingParameter(Name = "CustomSelect")]
public ICustomSelect CustomSelect { get; set; }

[Parameter]
public string Key { get; set; }

[Parameter]
public object Value { get; set; }

/// <summary>
/// When initialized, tell CustomSelect of this item
/// </summary>
protected override void OnInitialized()
{
CustomSelect.AddSelect(Key, Value);
}
}
}
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/DetailTemplate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class DetailTemplate<TableItem>
/// Content to show
/// </summary>
[Parameter]
public RenderFragment<TableItem> Template { get; set; }
public RenderFragment<TableItem> ChildContent { get; set; }

/// <summary>
/// When initialized, tell table of this item
Expand Down
3 changes: 1 addition & 2 deletions src/BlazorTable/Components/EmptyDataTemplate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace BlazorTable
/// <summary>
/// Child content for empty dataset
/// </summary>
/// <typeparam name="TableItem"></typeparam>
public partial class EmptyDataTemplate
{
/// <summary>
Expand All @@ -18,7 +17,7 @@ public partial class EmptyDataTemplate
/// Content to show
/// </summary>
[Parameter]
public RenderFragment Template { get; set; }
public RenderFragment ChildContent { get; set; }

/// <summary>
/// When initialized, tell table of this item
Expand Down
21 changes: 15 additions & 6 deletions src/BlazorTable/Components/FilterManager.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@ namespace BlazorTable
{
public partial class FilterManager<TableItem>
{
[CascadingParameter(Name = "Column")] public IColumn<TableItem> Column { get; set; }
[CascadingParameter(Name = "Column")]
public IColumn<TableItem> Column { get; set; }

[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }

[Inject] public ILogger<FilterManager<TableItem>> Logger { get; set; }
[Inject]
public ILogger<FilterManager<TableItem>> Logger { get; set; }

private void ApplyFilter()
{
Column.ToggleFilter();

if (Column.FilterControl != null)
{
Column.Filter = Column.FilterControl.GetFilter();
Column.Table.Update();
Column.Table.FirstPage();
} else
}
else
{
Logger.LogInformation("Filter is null");
}
Expand All @@ -28,8 +33,12 @@ private void ApplyFilter()
private void ClearFilter()
{
Column.ToggleFilter();
Column.Filter = null;
Column.Table.Update();

if (Column.Filter != null)
{
Column.Filter = null;
Column.Table.Update();
}
}
}
}
3 changes: 1 addition & 2 deletions src/BlazorTable/Components/LoadingDataTemplate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace BlazorTable
/// <summary>
/// Child content for null dataset
/// </summary>
/// <typeparam name="TableItem"></typeparam>
public partial class LoadingDataTemplate
{
/// <summary>
Expand All @@ -18,7 +17,7 @@ public partial class LoadingDataTemplate
/// Content to show
/// </summary>
[Parameter]
public RenderFragment Template { get; set; }
public RenderFragment ChildContent { get; set; }

/// <summary>
/// When initialized, tell table of this item
Expand Down
1 change: 0 additions & 1 deletion src/BlazorTable/Components/Pager.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace BlazorTable
/// <summary>
/// BlazorTable Pager
/// </summary>
/// <typeparam name="TableItem"></typeparam>
public partial class Pager
{
[CascadingParameter(Name = "Table")]
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorTable/Components/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
</tr>
</thead>
<tbody class="@TableBodyClass">
@if (TempItems != null)
@if (FilteredItems != null)
{
if (TempItems.Any())
if (FilteredItems.Any())
{
int i = 0;

foreach (TableItem item in TempItems)
foreach (TableItem item in FilteredItems)
{
<tr @key="item" class="@RowClass(item)">

Expand Down
Loading

0 comments on commit 7102ac1

Please sign in to comment.