How can i scroll to currently selected row in Vaadin grid?

Viewed 1704
    this.grid.asSingleSelect().addValueChangeListener(event -> {
        if (!Objects.isNull(event.getValue())) {
            this.editor.showEditor(event.getValue());
        }
    });

The problem is that editor covers half of grid when it's displayed. How can i scroll to selected row before showing it?

I know that you can this.grid.scrollTo(rowId);, but i can't find a way to get id of currently selected row.

2 Answers

grid#scrollTo

grid.scrollTo(rowForValue, ScrollDestination.START);

In Vaadin 8 you should able to use grid#getSelectedItems

public Set<T> getSelectedItems() 

method to get selected items, if your selection mode is single select, it returns set of one item.

Related