im trying to archieve the functionality in a Vaadin Grid to immediately select a row by arrow key navigation.
I couldnt find a possibility using ShortcutListener or FocusListener to react to the key events. By default the
Vaadin Grid focuses a Grid Cell when using arrow keys but not actually selects a row, this only works when hitting the
space bar afterwards. Is there a way to directly select the rows?
I start doubting whether it was good choice to select Vaadin as framework, as I want feature you mentioned … and after 3 years and new Vaadin 14 it is still not resolved :-/
Solved it by using a client-side Polymer component with Vaadin 14. To fire the selection event on the server-side you have to call grid.$server.select explicitly.
this.$.grid.addEventListener('keyup', event => {
const item = this.$.grid.getEventContext(event).item;
if (event.keyCode === 38 || event.keyCode === 40) { // arrow up || arrow down
this.$.grid.selectedItems = [item]
; // single selection
this.$.grid.$server.select(item.key);
}
});
Alex Gassner:
Solved it by using a client-side Polymer component with Vaadin 14. To fire the selection event on the server-side you have to call grid.$server.select explicitly.
this.$.grid.addEventListener('keyup', event => {
const item = this.$.grid.getEventContext(event).item;
if (event.keyCode === 38 || event.keyCode === 40) { // arrow up || arrow down
this.$.grid.selectedItems = [item]
; // single selection
this.$.grid.$server.select(item.key);
}
});
@Alex Gassner can you explain how you manage your script and files with Vaadin 14 ?
I mean do you have to create a js file with your script for content and then import it into a class extending from the Vaadin Grid class? Does your js file have any imports? I’m struggle with Polymer built into Vaadin.