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 #250 from NilsPur/master
Detail Template, Column Reordering, Custom Rows
- Loading branch information
Showing
12 changed files
with
309 additions
and
50 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
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 | ||
} | ||
} |
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,2 @@ | ||
@namespace BlazorTable | ||
@typeparam TableItem |
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,38 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using System; | ||
|
||
namespace BlazorTable | ||
{ | ||
/// <summary> | ||
/// A custom row template | ||
/// </summary> | ||
/// <typeparam name="TableItem"></typeparam> | ||
public partial class CustomRow<TableItem> : ComponentBase | ||
{ | ||
/// <summary> | ||
/// Parent Table | ||
/// </summary> | ||
[CascadingParameter(Name = "Table")] | ||
public ITable<TableItem> Table { get; set; } | ||
|
||
/// <summary> | ||
/// Function that defines if the custom row is active for the TableItem inserted as parameter | ||
/// </summary> | ||
[Parameter] | ||
public Func<TableItem, bool> IsActiveForItem { get; set; } | ||
|
||
/// <summary> | ||
/// Content to show | ||
/// </summary> | ||
[Parameter] | ||
public RenderFragment<TableItem> ChildContent { get; set; } | ||
|
||
/// <summary> | ||
/// When initialized, add custom row to table | ||
/// </summary> | ||
protected override void OnInitialized() | ||
{ | ||
Table.AddCustomRow(this); | ||
} | ||
} | ||
} |
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.