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
/
EditMode.razor
90 lines (80 loc) · 3.25 KB
/
EditMode.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@page "/EditMode"
@using BlazorTable
<h1>Edit Mode</h1>
<button class="btn btn-sm btn-danger" title="Toggle Edit Mode" @onclick="@((x) => ToggleEdit())">Toggle Edit Mode</button>
<br />
<br />
<Table TableItem="PersonData" Items="data" PageSize="15" @ref="Table" ColumnReorder="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true">
<EditTemplate>
<input type="number" @bind-value="@context.id" class="form-control form-control-sm" />
</EditTemplate>
</Column>
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%">
<EditTemplate>
<input type="text" @bind-value="@context.full_name" class="form-control form-control-sm" />
</EditTemplate>
</Column>
<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>
<EditTemplate>
<input type="email" @bind-value="@context.email" class="form-control form-control-sm" />
</EditTemplate>
</Column>
<Column TableItem="PersonData" Title="Paid" Field="@(x => x.paid)" Sortable="true" Filterable="true" Width="10%">
<Template>
@context.paid.ToString()
</Template>
<EditTemplate>
<input type="checkbox" @bind-value="@context.paid" class="form-control form-control-sm" checked="@(context.paid)" />
</EditTemplate>
</Column>
<Column TableItem="PersonData" Title="Price" Field="@(x => x.price)" Sortable="true" Filterable="true" Width="10%" Format="C">
<EditTemplate>
<input type="number" step=".01" @bind-value="@context.price" class="form-control form-control-sm" />
</EditTemplate>
</Column>
<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>
<EditTemplate>
<input type="date" @bind-value="@context.created_date" class="form-control form-control-sm" />
</EditTemplate>
</Column>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
@code
{
[Inject]
private HttpClient Http { get; set; }
private ITable<PersonData> Table;
private PersonData[] data;
protected override async Task OnInitializedAsync()
{
data = await Http.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
}
private void ToggleEdit()
{
Table.ToggleEditMode();
}
}