Update grid popup headers and edit form logic

CatalogsGrid now sets popup edit form header dynamically ("Neu" for new, "Edit" for existing) and only shows the "Update-Prozedur" field when editing. Added IsNew property to CatalogEditModel. MassDataGrid sets popup header to "Bearbeiten". Also standardized DateChanged event handler style in both components.
This commit is contained in:
OlgunR
2026-02-05 12:52:44 +01:00
parent 9bbe34dece
commit a52d615750
4 changed files with 60 additions and 32 deletions

View File

@@ -37,6 +37,7 @@ else
CssClass="mb-4 catalog-grid"
EditMode="GridEditMode.PopupEditForm"
PopupEditFormCssClass="catalog-edit-popup"
PopupEditFormHeaderText="@popupHeaderText"
CustomizeEditModel="OnCustomizeEditModel"
EditModelSaving="OnEditModelSaving"
DataItemDeleting="OnDataItemDeleting">
@@ -73,7 +74,7 @@ else
<DxGridDataColumn FieldName="@nameof(CatalogReadDto.AddedWhen)" Caption="Angelegt am" ReadOnly="true">
<FilterRowCellTemplate Context="filter">
<DxDateEdit Date="@((DateTime?)filter.FilterRowValue)"
DateChanged="@((DateTime? value) => filter.FilterRowValue = value)"
DateChanged="@((DateTime? value) => { filter.FilterRowValue = value; })"
Width="100%" />
</FilterRowCellTemplate>
</DxGridDataColumn>
@@ -87,13 +88,13 @@ else
<DxGridDataColumn FieldName="@nameof(CatalogReadDto.ChangedWhen)" Caption="Geändert am" ReadOnly="true">
<FilterRowCellTemplate Context="filter">
<DxDateEdit Date="@((DateTime?)filter.FilterRowValue)"
DateChanged="@((DateTime? value) => filter.FilterRowValue = value)"
DateChanged="@((DateTime? value) => { filter.FilterRowValue = value; })"
Width="100%" />
</FilterRowCellTemplate>
</DxGridDataColumn>
</Columns>
<EditFormTemplate Context="editFormContext">
@{ SetEditContext(editFormContext.EditContext); var editModel = (CatalogEditModel)editFormContext.EditModel; }
@{ SetEditContext(editFormContext.EditContext); var editModel = (CatalogEditModel)editFormContext.EditModel; SetPopupHeaderText(editModel.IsNew); }
<DxFormLayout ColCount="2">
<DxFormLayoutItem Caption="Titel">
<DxTextBox @bind-Text="editModel.CatTitle"
@@ -104,15 +105,18 @@ else
<DxFormLayoutItem Caption="Kennung">
<DxTextBox @bind-Text="editModel.CatString" Width="100%" />
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Update-Prozedur">
<DxComboBox Data="@procedureOptions"
TData="ProcedureOption"
TValue="int"
TextFieldName="Text"
ValueFieldName="Value"
@bind-Value="editModel.UpdateProcedure"
Width="100%" />
</DxFormLayoutItem>
@if (!editModel.IsNew)
{
<DxFormLayoutItem Caption="Update-Prozedur">
<DxComboBox Data="@procedureOptions"
TData="ProcedureOption"
TValue="int"
TextFieldName="Text"
ValueFieldName="Value"
@bind-Value="editModel.UpdateProcedure"
Width="100%" />
</DxFormLayoutItem>
}
<DxFormLayoutItem ColSpanMd="12">
<ValidationSummary />
</DxFormLayoutItem>
@@ -129,6 +133,7 @@ else
private string? infoMessage;
private EditContext? editContext;
private ValidationMessageStore? validationMessageStore;
private string popupHeaderText = "Edit";
private readonly List<ProcedureOption> procedureOptions = new()
{
@@ -184,11 +189,17 @@ else
editContext.NotifyValidationStateChanged();
}
private void SetPopupHeaderText(bool isNew)
{
popupHeaderText = isNew ? "Neu" : "Edit";
}
private void OnCustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
popupHeaderText = e.IsNew ? "Neu" : "Edit";
if (e.IsNew)
{
e.EditModel = new CatalogEditModel();
e.EditModel = new CatalogEditModel { IsNew = true };
return;
}
@@ -199,7 +210,8 @@ else
CatTitle = item.CatTitle,
CatString = item.CatString,
UpdateProcedure = 0,
OriginalCatTitle = item.CatTitle
OriginalCatTitle = item.CatTitle,
IsNew = false
};
}
@@ -351,6 +363,7 @@ else
public string CatString { get; set; } = string.Empty;
public int UpdateProcedure { get; set; }
public string OriginalCatTitle { get; set; } = string.Empty;
public bool IsNew { get; set; }
}
private sealed class ProcedureOption

View File

@@ -82,6 +82,7 @@ else
PageSize="100"
CssClass="mb-3 massdata-grid"
EditMode="GridEditMode.PopupEditForm"
PopupEditFormHeaderText="Bearbeiten"
EditModelSaving="OnEditModelSaving"
DataItemDeleting="OnDataItemDeleting">
<Columns>
@@ -129,14 +130,14 @@ else
<DxGridDataColumn FieldName="@nameof(MassDataReadDto.AddedWhen)" Caption="Added" ReadOnly="true">
<FilterRowCellTemplate Context="filter">
<DxDateEdit Date="@((DateTime?)filter.FilterRowValue)"
DateChanged="@((DateTime? value) => filter.FilterRowValue = value)"
DateChanged="@((DateTime? value) => { filter.FilterRowValue = value; })"
Width="100%" />
</FilterRowCellTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="@nameof(MassDataReadDto.ChangedWhen)" Caption="Changed" ReadOnly="true">
<FilterRowCellTemplate Context="filter">
<DxDateEdit Date="@((DateTime?)filter.FilterRowValue)"
DateChanged="@((DateTime? value) => filter.FilterRowValue = value)"
DateChanged="@((DateTime? value) => { filter.FilterRowValue = value; })"
Width="100%" />
</FilterRowCellTemplate>
</DxGridDataColumn>