-
Notifications
You must be signed in to change notification settings - Fork 2
/
Index.razor
69 lines (58 loc) · 2.37 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
59
60
61
62
63
64
65
66
67
68
69
@page "/"
@using ShowConfirmationDialog.Data
@inject WeatherForecastService ForecastService
<DxGrid @ref="Grid" Data="Forecasts"
EditMode="GridEditMode.EditRow"
EditModelSaving="Grid_EditModelSaving"
CssClass="mw-1100">
<Columns>
<DxGridCommandColumn NewButtonVisible="false" DeleteButtonVisible="false">
<CellDisplayTemplate>
<DxButton Click="() => GridEditButton_Click(context)" Text="Edit" RenderStyle="ButtonRenderStyle.Link" />
</CellDisplayTemplate>
</DxGridCommandColumn>
<DxGridDataColumn Caption="Date" FieldName="Date" />
<DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" />
</Columns>
</DxGrid>
<DxPopup @bind-Visible="IsPopupVisible" HeaderText="Modify a Record" ShowCloseButton="true" Closed="Popup_Closed">
<BodyContentTemplate>
<p>Your data item has been modified. Do you want to save your changes?</p>
<div class="confirmation-dialog-content">
<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Yes" Click="ButtonSave_Click" />
<DxButton RenderStyle="ButtonRenderStyle.Secondary" Text="No" Click="ButtonCancel_Click" />
</div>
</BodyContentTemplate>
</DxPopup>
@code {
List<WeatherForecast> Forecasts { get; set; }
IGrid Grid { get; set; }
object SavedDataItem { get; set; }
bool IsPopupVisible { get; set; }
protected override async Task OnInitializedAsync() {
Forecasts = await ForecastService.GetForecastAsync(DateTime.Now.AddDays(-2));
}
async Task GridEditButton_Click(GridCommandColumnCellDisplayTemplateContext context) {
if (context.Grid.IsEditing() && context.Grid.GetEditContext().IsModified()) {
SavedDataItem = context.DataItem;
IsPopupVisible = true;
} else
await context.Grid.StartEditDataItemAsync(context.DataItem);
}
void Grid_EditModelSaving(GridEditModelSavingEventArgs e) {
e.CopyChangesToDataItem();
}
async Task ButtonSave_Click() {
await Grid.SaveChangesAsync();
IsPopupVisible = false;
}
async Task ButtonCancel_Click() {
IsPopupVisible = false;
}
async Task Popup_Closed() {
if(SavedDataItem != null) {
await Grid.StartEditDataItemAsync(SavedDataItem);
SavedDataItem = null;
}
}
}