Skip to content
Advertisement

Mark row selected on mouse click in vaadin grid(SelectionMode.MULTI)

I have a Grid with a multi-select option. In a normal way when I click in the checkbox the row is selected with the default selected color. But I need to have the same or other selected color when I click in the grid´s row.

I have created a CSS:

JavaScript

Imported it in my class view:

JavaScript

The code above works when the grid is loaded, but when the row is clicked nothing happens. What can I put in the addItemClickListener to fire again setClassNameGenerator?

Or what can I do to have the line selected when the row is clicked?

Advertisement

Answer

In multi-selection mode, the item is selected when clicking the checkbox, but not when clicking anywhere in the row. If you want to select the item in response to a row click, you can do:

JavaScript

Alternatively, if you want to update the row styles without selecting the item, you need to call refreshItem (which will cause the ClassNameGenerator to be evaluated again for that row)

JavaScript

There is a live demo using similar approach in Vaadin’s Cookbook.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement