Hi,
I am using the Radzen Blazor components in a standalone Blazer Server side project, I am using a RadzenDataGrid, which is populated from a List object, however when I remove or add items from that list, the RadzenGrid is not automatically refreshing. (IE seems not to look at StateHasChanged), so I thought I might get an @ref to the object and attempt to call the .Reload() method, however this seems to work for other objects that are not a Radzen Data Grid, but not to work for a RadzenData grid itself, as the data variable does not seem to being assigned when the grid is initialized rendered. Here is my Blazor which Renders the RadzenDataGrid:
<RadzenDataGrid @ref="gridUserOwnedContracts" AllowFiltering="true"
FilterMode="FilterMode.Simple" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
Data="@userOwnedContracts" TItem="Contract">
<RadzenDataGridColumn TItem="Contract" Title="Client">
<Template Context="contract">
@contract?.Client?.ClientName
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Contract" Title="Availability">
<Template Context="contract">
@contract?.Island?.IslandAvailabilityName
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Contract" Title="Contract" Property="ContractName"/>
<RadzenDataGridColumn TItem="Contract" Title="Project" Property="ProjectNumber"/>
<RadzenDataGridColumn TItem="Contract" Title="" Width="120px">
<Template Context="contract">
<button class="btn btn-danger btn-sm"
@onclick="@(e => RemoveContract(contract))">
Remove
</button>
</Template>
</RadzenDataGridColumn>
</RadzenDataGrid>
And where I declare the object that I am using @ref to point to - note I had to template this based on the base object in the table...
private RadzenDataGrid<Contract> gridUserOwnedContracts;
And where I declare the List that I am populating the RadzenDataGridWith
private List<Contract> userOwnedContracts;
And my method that is tied to the - remove button above that when I execute it looks like the grid object has not been initialised:
protected void RemoveContract(Contract c, bool RefreshTables=true)
{
userOwnedContracts.Remove(c);
userNotOwnedContracts.Add(c);
if (RefreshTables)
{
gridUserOwnedContracts.Reload();
}
}
Or alternatively if RadzenDataGrid could automatically detect when the List has changed then I would not need to use the Reload() method, however it does not appear to be detecting when I add or remove items from the underlying List object, and also when i use the @ref= construct so I can reference the underlying object to use Reload() etc - that seems not to initialize correctly as well. Or am I missing something?