Blazor: Unable to add new item to Grid

I love the Blazor Grid. But it seems to be missing the ability to add new items to the underlying data source. I was able to wire up a KendoUI clone of the BlazorGrid by creating my own header div with an "Add New Record" button, which called the following code:

var entity = new Entity();
Entities.Insert(0, entity);
grid.EditRow(entity);

Where grid is the Grid instance and Entities is the List that is that data source for the Grid.

This worked fine in the 1.x branch of the Blazor controls, but now no longer works. I've tried different permutations of StateHasChanged, including using an ObservableCollection and wiring StateHasChanged to the CollectionChanged handler, or calling grid.Reload()after the Entities are inserted... nothing works.

Any ideas on how to fix this?

Thanks!

Robert McLaws, BurnRate.io

Hi @RobertMcLaws,

This all sounds as this issue. Try the following:

var entity = new Entity();
Entities.Insert(0, entity);

Entities = Entities.ToList(); // Update the reference so the DataGrid refreshes its cache

grid.EditRow(entity);
StateHasChanged();

We will add built-in insert support in one of the next releases.

Perfect, that fixed it. Thanks so much for your help! :slight_smile: