Home > OS >  How to reload Radzen DataGrid manually without refreshing page?
How to reload Radzen DataGrid manually without refreshing page?

Time:11-18

I created a button to reload a Radzen DataGrid on Blazor.

The datagrid is supposed to be reloaded after I click the button.

However, nothing happened when I clicked the button.

Button

<RadzenButton Click=@(args => Refresh()) Icon="refresh" ButtonStyle="ButtonStyle.Light" />

Radzen DataGrid

<RadzenDataGrid @ref="grid" Data="@records" TItem="class" ...>

Blazor Coding

IEnumerable<class> records;
RadzenDataGrid<class> grid = new RadzenDataGrid<class>();

async Task Refresh() 
{ 
    records = Service.GetAllRecords();
    await grid.Reload();
    InvokeAsync(StateHasChanged);
} 

Service

public List<class> GetAllRecords() 
    {
        return _db.records.Include(r => r.a).Include(r => r.b).OrderByDescending(r=>r.id).ToList();
    }

CodePudding user response:

MrC aka Shaun Curtis is correct.
Simply change the codes of GetAllRecords and make it an async function.
Then use await in Refresh().
It would work.

  • Related