Best practice for updating Grid item on binder changes

Hi

I’m writing an application heavely based on the grid component where the client selects an item in the grid and this changes the binder for the form to edit the specific item. This works great, but I also want to update the item in the grid to mach the changes. Name changed etc should also be updated in the grid.

I have solved this a couple of ways using both GridListDataView and directly addItems when binder changes, but it feels a bit off since the selection changes when I do that…

Any pointers to a best practice here?

You can refresh a single item in a grid, you could do that for example together with a valueChangeListener on the binder.

// this is Vaadin14 Syntax, not sure if this has changed since then
binder.addValueChangeListener(changeEvent -> {
    // warning: binder.getBean() won't work if you use the binder with readBean/writeBean
    grid.getDataProvider().refreshItem(binder.getBean());
});