While editing a grid row, how can I update *other* rows?

Say I have an editable grid, using an unbuffered editor.
The rows are periods, with start-date and end-date.
Using the grid editor, I set start-date on row N, and on valueChanged I want to set end-date on row N-1 to the same.

If I refresh row N-1, the editor closes, which is bad ux.

I previously had a similar issue with updating non-editable fields on the edited row.
That was fixed by having a fake read-only TextField editor for these as well.
Ugly, but works.

I can probably use the same approach for my current case, but now I have to use ComponentRenderer to render read-only TextFields on all rows :frowning:

It would really be useful if:

  • I could refresh a row without closing the editor
  • I could refresh a cell

I ran into this recently as well and was kind of surprised that it always closes the editor even when refreshing an unrelated item. So I did take a look. By default, Grid always closes the editor when there is a change in the data provider, regardless whether you refresh all items or a single item: flow-components/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java at 53d36a0c7e518402624429a759b924d02ca359fd · vaadin/flow-components · GitHub

But that method is protected, so that behavior can be customized. I outlined a custom Grid below that would only close the editor if the currently edited item, or all items are refreshed:

public class CustomGrid<T> extends Grid<T> {
    @Override
    protected void onDataProviderChange() {
        // Do not close the editor by default
    }

    public void refreshItem(T item) {
        getDataProvider().refreshItem(item);

        // Cancel / close the editor if the item is being edited
        if (item.equals(getEditor().getItem())) {
            super.onDataProviderChange();
        }
    }

    public void refreshAll() {
        getDataProvider().refreshAll();

        // Always cancel / close the editor
        super.onDataProviderChange();
    }
}

And if you don’t want to close the editor when refreshing the currently edited item, I guess you could also just update the editor instead of closing it.

Nice :smile:
I’ll try that right away.

I already do that; I keep track of the editor fields and if I’m updating a cell with an editor field, I update the field instead. Which is another thing that a grid.refreshCell could do.

Also, as mentioned above, I create a read-only TextField “editor” for everything that doesn’t have a proper editor but I want to be refreshable on the editor-row. It is an annoying cludge, but it works.

I’m getting some weird behaviour; I have a checkbox that sets or clears all values. When editor is closed everything works fine. When editor is open and I click this checkbox on other lines, it looks like I can set or clear once per row. After that it doesn’t work.

Strange thing is that it seems like the request responses contain the expected values. It just doesn’t redraw.

If I open/close the editor on those rows they redraw correctly.

I’ll see if I can create a testcase on monday

I’ve created a testcase now, and everything works as expected, so looks like whatever the issue is, it is somewhere in my app, and not in Vaadin.