Radzen grid Reload not working when initial data is 0 in length

Hi there, I'm having an issue with reloading the grid. I have a Radzen dialog for a user to enter a value, and then that to get loaded into the grid when the dialog is submitted.

I've got that to work when there are already values in the grid, but when the list is empty (i.e. the grid is showing 'No records to display.'), the grid doesn't reload. Debugging, I can see my empty list and my new value getting added to the list.

This is the code for my dialog and reloading the grid:

public async Task OpenAddProperty()
{
var result = await DialogService.OpenAsync(
"New Property",
parameters: new Dictionary<string, object>
{
{ "Client", client! }
},
options: new DialogOptions() { Width = "700px" });

    if (result != null && propertyGrid != null && result is Property)
    {
        var newProperty = result as Property;
        this.properties!.Add(newProperty!);

        if (propertyGrid != null)
        {
            await propertyGrid!.Reload();
            StateHasChanged();
        }            
    }

}

Hi @coffeymatt,

What is your RadzenDataGrid configuration? The provided code does not show it.

Here's the grid code:

                    <RadzenDataGrid @ref="propertyGrid"
                            IsLoading="@propertiesLoading"
                            Count="@propertyCount"
                            Data="@properties"
                            AllowSorting="true"
                            AllowFiltering="false"
                            AllowPaging="true"
                            PageSize="20"
                            PagerHorizontalAlign="HorizontalAlign.Center"
                            TItem="Property"
                            ColumnWidth="200px">
                        <Columns>
                            <RadzenDataGridColumn TItem="Property" Property="Name" Title="Property Name" />
                            <RadzenDataGridColumn TItem="Property" Context="property" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="40px">
                                <Template Context="property">
                                    <a class="btn btn-info btn-xs" href="@($"/client/{@client.Id}/property/{property.Id}")">
                                        <em class="pli-pen-4"></em>
                                        Edit
                                    </a>
                                </Template>
                            </RadzenDataGridColumn>
                        </Columns>
                    </RadzenDataGrid>

Does it work if you change this to

this.properties = this.properties.Append(newProperty)

I've tried that change, doesn't seem to make any difference, still stays at 'no records to display' on the grid until I refresh the browser. Once there are records, it works.

Have you updated propertyCount to reflect the total number of items?

1 Like

Well done, that was it, doh! :face_with_peeking_eye: