I want to create a DataGrid that input the commission rate of different years. But this table should be horizontal instead of vertical as below:
<RadzenDataGrid @ref="DynamicRateGrid" TItem="IDictionary<int, decimal?>" Data="@RateListDict"
AllowPaging="false" AllowColumnResize="true">
<EmptyTemplate>
<p style="color: lightgrey; font-size: 24px; text-align: center; margin: 2rem;">No records to display.</p>
</EmptyTemplate>
<Columns>
<RadzenDataGridColumn Title="Year" Width="80px">
<Template Context="context1">
<div>Rate</div>
</Template>
</RadzenDataGridColumn>
@foreach (var year in YearList)
{
<RadzenDataGridColumn TItem="IDictionary<int, decimal?>" Title="@year.ToString()" TextAlign="TextAlign.Center" CssClass="rz-p-1" Width="70px">
<Template Context="context1">
@(context1.TryGetValue(year, out var value))
<RadzenNumeric TValue="decimal?" ShowUpDown="false" Value="@(value * 100)" Change="@(a => OnRateChange(year, a))" class="rz-p-1"></RadzenNumeric>
</Template>
</RadzenDataGridColumn>
}
<RadzenDataGridColumn>
<Template Context="context1">
<RadzenButton Icon="add" ButtonStyle="ButtonStyle.Primary" Variant="Variant.Flat" Size="ButtonSize.Medium" class="my-1 ms-1" Click="@((args) => AddRate())" @onclick:stopPropagation="true"></RadzenButton>
<RadzenButton Icon="delete" ButtonStyle="ButtonStyle.Danger" Variant="Variant.Flat" Size="ButtonSize.Medium" class="my-1 ms-1" Click="@((args) => DeleteRate())" @onclick:stopPropagation="true"></RadzenButton>
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
private List<Dictionary<int, decimal?>> RateListDict = [];
private void AddRate()
{
var key = RateListDict.First().Keys.Max() + 1;
RateListDict.First().Add(key, null);
DynamicRateGrid.Reload();
StateHasChanged();
}
private void DeleteRate()
{
RateListDict.First().Remove(RateListDict.First().Keys.Max());
DynamicRateGrid.Reload();
StateHasChanged();
}
The DataGrid does not show/remove the column after clicking the add/delete button even the Dictionary was updated.