Force refresh on Blazorise DataGrid

3.3k Views Asked by At

how do you force a refresh on a Blazorise DataGrid? The scenario is a Page Size component changes the page size from 5 to 10 and the grid should be refreshed with the new Page Size. Despite the grid being bound to PageSize, the ReadData event does not fire.

1

There are 1 best solutions below

2
Mladen Macanović On BEST ANSWER

This is how I usually do it.

First, save event arguments for OnReadData

private DataGridReadDataEventArgs<Order> lastDataRead;

and

private async Task OnReadData( DataGridReadDataEventArgs<Order> e )
{
    lastDataRead = e; // save every time, so you can refresh later

    var result = await OrderApi.GetAllByUser( ... );

    ...

    StateHasChanged();
}

And then when you need to refresh just call OnReadData

await OnReadData( lastDataRead ?? new DataGridReadDataEventArgs<Order>( 0, 10, null ) );

Obviously, you would need to reapply event args with the page number and page size according to your scenario.