-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.razor
58 lines (53 loc) · 2.24 KB
/
Index.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
@page "/"
@using DisableEditButton.Data
@inject WeatherForecastService ForecastService
@if (forecasts == null) {
<p><em>Loading...</em></p>
}
else {
<DxGrid @ref="myGrid" Data="@forecasts" EditModelSaving="OnEditModelSaving">
<Columns>
<DxGridCommandColumn NewButtonVisible=false>
<CellDisplayTemplate>
@{
var date = context.DataItem != null ? (context.DataItem as WeatherForecast).Date : DateTime.Now;
<DxButton Text="Edit"
RenderStyle="ButtonRenderStyle.Link"
Click="() => myGrid.StartEditDataItemAsync(context.DataItem)"
Enabled="@(date >= DateTime.Now)" />
}
</CellDisplayTemplate>
</DxGridCommandColumn>
<DxGridDataColumn Caption="Date" FieldName="Date"/>
<DxGridDataColumn Caption="Summary" FieldName="Summary"/>
<DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC"/>
<DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF"/>
</Columns>
<EditFormTemplate Context="editFormContext">
<DxFormLayout>
<DxFormLayoutItem Caption="Date:">
@editFormContext.GetEditor("Date")
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Summary:">
@editFormContext.GetEditor("Summary")
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Temperature (C):">
@editFormContext.GetEditor("TemperatureC")
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Temperature (F):">
@editFormContext.GetEditor("TemperatureF")
</DxFormLayoutItem>
</DxFormLayout>
</EditFormTemplate>
</DxGrid>
}
@code {
List<WeatherForecast>? forecasts;
IGrid myGrid { get; set; }
protected override async Task OnInitializedAsync() {
forecasts = await ForecastService.GetForecastAsync(DateTime.Now.AddDays(-2));
}
void OnEditModelSaving(GridEditModelSavingEventArgs e) {
e.CopyChangesToDataItem();
}
}