Hello,
I have this master-detail data grid. I removed the details for simplicity.
<RadzenButton Icon="add_circle_outline" style="margin-bottom: 10px" Text="Add New Order" Click="@InsertRow" Disabled="@(_orderToInsert != null)"/><RadzenButton Text="Export XLS" Icon="grid_on" Click="@(args => ExportExcel())" Class="mb-4 mr-2" />
<RadzenDataGrid @ref="_grid" AllowFiltering="true" AllowPaging="true" PageSize="7" AllowSorting="true" RowClick="RowClick" ExpandMode="DataGridExpandMode.Single"
Data="@_orders" TItem="Order" EditMode="DataGridEditMode.Single" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" @bind-Value="@SelectedOrders"
ShowExpandColumn="false" ShowPagingSummary="true" AllowColumnResize="true" >
<Template Context="order">
<RadzenCard Style="margin-bottom: 20px">
Customer:
<b>@order?.Customer?.Name</b>
</RadzenCard>
<RadzenTabs>
<Tabs>
<RadzenTabsItem Text="Order Details">
<div id="wrapper">
<RadzenButton Icon="add_circle_outline" style="margin-bottom: 10px" Text="Add Order Detail" Click="@(() => InsertDetailRow(order.Id))" Disabled="@(_detailToInsert != null)"/>
<RadzenButton Text="Export XLS" Icon="grid_on" Click="@(args => ExportDetailExcel())" Class="mb-4 mr-2" />
<RadzenButton Icon="close" id="c3" style="margin-bottom: 10px;" ButtonStyle="ButtonStyle.Light" Click="@(args => CancelEdits(SelectedOrders.FirstOrDefault()?.OrderDetails))" />
<RadzenButton Icon="save" style="margin-bottom: 10px; margin-right: 10px" Text="Save Details" id="c2" Click="@(args => SaveRowDetails(SelectedOrders.FirstOrDefault()?.OrderDetails))"/>
<RadzenButton Icon="border_color" style="margin-bottom: 10px; margin-right: 10px" Text="Edit Details" id="c1" Click="@(args => EditRowDetails(SelectedOrders.FirstOrDefault()?.OrderDetails))" @onclick:stopPropagation="true"/>
</div>
<RadzenDataGrid @ref="_gridDetail" AllowFiltering="true" AllowPaging="true" PageSize="5" AllowSorting="true" Data="@order.OrderDetails"
TItem="OrderDetail" EditMode="DataGridEditMode.Multiple" RowUpdate="@OnUpdateRowDetail" RowCreate="@OnCreateRowDetail" AllowColumnResize="true"
AllowColumnPicking="true" ShowPagingSummary="true" ColumnWidth="150px" >
<Columns>
<RadzenDataGridColumn TItem="OrderDetail" Property="Id" Title="Product Number" Frozen="true" OrderIndex="1"/>
<RadzenDataGridColumn TItem="OrderDetail" Property="ProductCode" Title="Code" Frozen="true" OrderIndex="2">
<EditTemplate Context="orderDetail">
<RadzenTextBox @bind-Value="orderDetail.ProductCode" Style="width: 100%; display: block" Name="ProductCode"/>
<RadzenRequiredValidator Text="Product Code is required" Component="ProductCode" Popup="true" Style="position: absolute"/>
</EditTemplate>
</RadzenDataGridColumn>
...
<RadzenDataGridColumn TItem="OrderDetail" Property="CustomerOrderNumber" Title="Customer Order" OrderIndex="19">
<EditTemplate Context="orderDetail">
<RadzenTextBox @bind-Value="orderDetail.CustomerOrderNumber" Style="width: 100%; display: block" Name="CustomerOrderNumber"/>
</EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="OrderDetail" Property="OrderId" Title="Order Id" OrderIndex="20"/>
<RadzenDataGridColumn TItem="OrderDetail" Context="orderDetail" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="200px" OrderIndex="20">
<Template Context="detail">
<RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => EditRowDetail(detail))" @onclick:stopPropagation="true">
</RadzenButton>
</Template>
<EditTemplate Context="detail">
<RadzenButton Icon="check" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => SaveRowDetail(detail))">
</RadzenButton>
<RadzenButton Icon="close" ButtonStyle="ButtonStyle.Light" Class="m-1" Click="@(args => CancelEditDetail(detail))">
</RadzenButton>
<RadzenButton Icon="delete" ButtonStyle="ButtonStyle.Danger" Class="m-1" Click="@(args => ShowInlineDialog(detail))">
</RadzenButton>
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
</RadzenTabsItem>
</Tabs>
</RadzenTabs>
</Template>
<Columns>
<RadzenDataGridColumn TItem="Order" Property="Id" Title="Order ID" Width="120px"/>
<RadzenDataGridColumn TItem="Order" Property="Customer.Name" Title="Customer" Width="200px">
<EditTemplate Context="order">
<RadzenDropDownDataGrid TValue="int" AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains"
Data=@_customers Count="5" TextProperty="Name" ValueProperty="Id"
Class="w-100" @bind-Value="order.CustomerId"/>
</EditTemplate>
</RadzenDataGridColumn>
...
<RadzenDataGridColumn TItem="Order" Context="order" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="120px">
<Template Context="order">
<RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => EditRow(order))" @onclick:stopPropagation="true">
</RadzenButton>
</Template>
<EditTemplate Context="order">
<RadzenButton Icon="check" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => SaveRow(order))">
</RadzenButton>
<RadzenButton Icon="close" ButtonStyle="ButtonStyle.Light" Class="m-1" Click="@(args => CancelEdit(order))">
</RadzenButton>
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
I have orders and details on my master-detail data grid. When I click on an order (19), details open (2 details in this screenshot).
When I click edit details, these 2 records become editable. So far so good.
If I change some fields and click save details, changes save. (2nd column from right changed.)
If I add an order detail by clicking the add order detail button a new row is added to the details. I enter data and save them.
Now, If I click edit details, the newly added row does NOT become editable.
Here is the code portions:
async Task EditRowDetails(IList<OrderDetail?> SelectedOrders)
{
foreach (var detail in SelectedOrders)
{
await _gridDetail.EditRow(detail);
}
}
async Task SaveRowDetails(IList<OrderDetail?> SelectedOrders)
{
var id = 0;
foreach (var detail in SelectedOrders)
{
id = detail.OrderId;
if (detail == _detailToInsert)
{
_detailToInsert = null;
}
await _gridDetail.UpdateRow(detail);
}
if(SelectedStatus != null && (SelectedStatus.ToString() == "Completed" || SelectedStatus.ToString() == "Cancelled")){
var order = await ViewOrdersByStatusUseCase.ExecuteAsync(SelectedStatus.ToString(), id);
if (order != null)
{
order.Status = SelectedStatus.ToString();
await EditOrderUseCase.ExecuteAsync(order);
}
}
}
private async Task InsertDetailRow(int id)
{
_detailToInsert = new OrderDetail
{
OrderId = id
};
await _gridDetail.InsertRow(_detailToInsert);
}