Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Grid - RowReference inside Renderer/Converter
I have a use case where the presentation of a cell is depending on the row-item.
Is there a way to get a reference to the item id from a renderer/converter (best case: using server side only)?
How could I solve this?
Converter doesn't have any access to rowreference, since it is very generic and can be used in other places than Grid too.
Renderer clientside part has access to RowReference. If you want to use that information in serverside you need to implement custom renderer for your purpose and and use RPC to update the RowReference to serverside.
As an example you could check how this Renderer connector access value from a cell.
Thanks for your quick answer. I had a look and am currently trying to implement this.
Unfortunately it seems that my custom state is not used. Is it really sufficient to override the getState() Method and cast super.getState() to my custom state? Or is there anything additionally I have to do?
The custom rpc is not needed if I do not need any events, right?
Using getState() on the server side always gives me a class cast exception as its the usual SharedState class and not my custom state.
What somehow really surprises me is this method:
How am I supposed to use this in the renderer? How to I get the rowKey?
The documentation states: "This method can be used to get the item id for the row key that the client has sent".
So where is it sent and how can I get it?
You can for example add some listener in the renderer client-side implementation and send the row key obtained from the client-side event to the server side. It's intended for providing client-side events to the server-side with the related information (item id, item, column, etc.)
Hello, thank you for the explanation :)
So what would you suggest if the rendering of a single column depends on a value of the row item?
this seems to work. But unfortunately now I cant sort the column anymore. Any solutions to this?
You can implement the sorting for a generated property by implementing the getSortProperties method in your PropertyValueGenerator. That method returns what original properties need to be sorted instead of the generated column in question.