Hello, there is an issue with the follwoing code, I can't understand.
If I run the code below, the RadzenDataGrid will show 'No records to display'. But the line <div>Kunde: @customerList[0].LastName</div>
shows the correct result.
If I move the allocation customerList = new();
after the await Wait(1000);
command, the grid shows the correct result.
If I take the code like below and I replace the RadzenDataGrid
through RadzenGrid
and RadzenDataGridColumn
through RadzenGridColumn
, everything works like expected. The grid shows the data.
Is this a bug, or are I'm something missing?
@page "/Test"
<div>Counter: @counter.ToString()</div>
@if (customerList != null && customerList.Count() > 0)
{
<div>Kunde: @customerList[0].LastName</div>
}
<RadzenDataGrid Data="@customerList" TItem="Customer">
<Columns>
<RadzenDataGridColumn TItem="Customer" Property="LastName" Title="Last Name" Width="250px" />
<RadzenDataGridColumn TItem="Customer" Property="FirstName" Title="First Name" Width="150px" />
</Columns>
</RadzenDataGrid>
@code{
public List<Customer>? customerList;
int counter = 0;
Customer customer = new() { LastName = "Doe", FirstName = "John" };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
customerList = new();
await Wait(1000);
counter++;
// If I do the allocation here, it works like intendet
//customerList = new();
customerList.Add(customer);
}
private async Task Wait(int millisec)
{
await System.Threading.Tasks.Task.Delay(millisec);
}
public class Customer
{
public string FirstName { get; set; } = "";
public string LastName { get; set; } = "";
}
}