2

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();
    }
AsM
  • 91
  • 1
  • 10
  • Is `records = Service.GetAllRecords();` really a sync method that runs to completion before the next step? It would appear that records isn't updated before the rest of the code in `Refresh` completes. Can you show `GetAllRecords`? – MrC aka Shaun Curtis Nov 15 '22 at 08:24
  • Thank you for the comment. I have updated my question. I think I am facing the problem you mentioned. – AsM Nov 16 '22 at 00:46

1 Answers1

1

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.

AsM
  • 91
  • 1
  • 10