How can I refresh grid row while editing it?

In a grid, I have an editable code with a corresponding non-editable description.
When the code changes, I want to update the description.
If I call dataProvider.refreshItem, the editor is closed as well.

Do I have to add anything I expect to be updated while the editor is open as read-only editable fields and do instead?

It would’ve been nice to have a dataProvider.refreshCell or something

This is a tricky scenario which can have various corner cases.

I assume you are using Grid’s integrated row editor, right. When you are refreshing an item, editor would need to be re-populated. Conflicts are possible, what to do with those?

The most straightforward way to handle this in the application is that you close the editor, refresh item and then re-open the editor programmatically again. This means that current edits are lost and replaced with what ever are being refreshed to the item.

You can implement logic in other direction as well. E.g. you could persists the values being edited (provided that Binder is valid). I.e. what ever is being refreshed is being discarded in favor of edited.

Just noting here, that Binder has also writeBeanAsDraft method, which allows you to save non-valid data to temporary bean, and write more sophisticate logic to resolve the data from refresh vs. edits problem. Binder for example has a method to get changed bindings, if you want to replace un-edited from refresh values and save edits.

There are small variations how to do this depending whether you use the editor in buffered or non-buffered mode.

As you see, if this would be built-in feature in Grid, it would require rather complex API to control its behavior and still possibly allow totally custom logic to be called as applications tend to vary.

Currently framework API’s cover only the low layer here (i.e. Binder) and what ever you do is DIY.

For a buffered editor it would not make sense to update the fields outside the editor. In that case you should have everything you want to update inside the editor.

For a non-buffered editor, which I use, there should be no problem refreshing cells outside the editor, other than that there is no api for it, or?

re-opening the editor would mean losing input focus and tab position, which would be awful UX for anyone navigating with keyboard.

Sounds like I have to set an editorComponent on all updatable columns.

I do not fully understand your use case. It now feels that correct action for you would be to test if the Editor is open and check the item being edited, and if it is the same one to be refreshed, you simply do not refresh. It really does not make sense update Grid row, that is being edited, if you simply do not want the editor to be updated. Also noting, that if you would merge the backfilled properties to edited ones, the you would still have focus / editor caret position UX issue. If I would implement some sort of update with backfilled data in the editor, I would probably show ConfirmDialog and ask user if he/she wants to accept backfilled data. In that process the UX is more clear.

I don’t understand what you don’t understand :smiley:
Let me make it more concrete. Here is my use-case:

  • Editor is non-buffered
  • User enters an ID
  • My code looks up that id and updates the “Name” column in the dataProvider
  • I’d like this new “Name” value to be reflected in the grid.
  • Currently, “Name” has no editor. It is just a regular text column

Correct me if I’m wrong, but “Name” is completely outside the editor; I’m seeing the exact same text as before the editor was opened? (ie there is no “overlay” like in Vaadin7) So, if I could refresh “Name” it should not impact the editor in any way?

I accept that it is not possible today, but I think it should be.

For now I’ll create a fake editor for Name, so that I can do and see where that takes me

Make it a read only text field and update that: problem solved

Thanks for sharing the use scenario. That makes the discussion much easier to understand. I was in a wrong impression that you had some sort of concurrency case, i.e. some other person editing the row at the same time and hence getting backfilled by refreshing the item.

That is the plan, but it is not pretty.

This was not an isolated case. The business logic can update anything, so for a robust solution I have to either tag everything that can be updated, or generate editor fields for everything. So, Grid is forcing me to do extra work.

Ideally, I should be able to do grid.refreshCell(row,col) and grid should handle the editor/not editor situation

Actually, Grid had similar issues in Vaadin7 (then due to the editor overlay having non-changeable copies of all non-editable cells), so it looks like I’ve already tagged the columns that need to have a fake editor. Puh.