Problem with DataGrid's Reload()

Upon initializing DataGrid displays all the test data as shown below:

The DataGrid is defined as below:

<RadzenDataGrid
  @ref                    ="@_grid"
  AllowFiltering          ="true"
  AllowRowSelectOnRowClick="true"
  FilterMode              ="FilterMode.Advanced"
  Data                    ="@Presenter?.Parts"
  RowDeselect             ="OnRowDeselect"
  RowSelect               ="OnRowSelect"
  SelectionMode           ="DataGridSelectionMode.Multiple"
  TItem                   ="Part">

Presenter.Parts is simply a List. Again, after the initialization, the grid is displaying fine.

Then I proceed to delete one of the rows by removing an element from Presenter.Part.

Parts?.RemoveAll(p => parts.Contains(p));

After that, I invoke the Reload() and StateHasChanged().

_grid?.Reload();
InvokeAsync(StateHasChanged);

This is when the grid gets "out-of-sync".

The Parts property has count of 3.

But somehow, _view of the DataGrid only has 2.

What am I missing? As always, thank you!

You need to change the reference otherwise the DataGrid will not know that Presenter.Parts has changed. Something like

Presenter.Parts = Presenter.Parts.ToList();

1 Like

For the folks who might be looking at this,

I used:

_grid.Data = Presenter?.Parts?.ToList();

This is done before the Reload().

@jwu How to keep the row expanded after delete or add?