schaphekar
schaphekar

Reputation: 495

Is there a way to auto-scroll horizontally in a Vaadin Grid?

Currently using Vaadin 23 and was wondering if it was possible to use scroll horizontally within a Grid programmatically, much like some of the built-in functionality with scrolling to the top or bottom row. However, in this case I would like to scroll using a column as reference (while maintaining the current vertical scroll position).

Upvotes: 1

Views: 524

Answers (1)

One idea would be to put a component into the column header, and then scroll to that component. Something like:

Grid.Column<SamplePerson> emailColumn = grid.addColumn("email");
Span emailHeaderText = new Span("Email");
emailColumn.setHeader(emailHeaderText);

Button scrollToEmail = new Button("Scroll", e -> 
    emailHeaderText.scrollIntoView()
);

It doesn't work perfectly, as the header component does not cover the whole column width, but it might be good enough.

Upvotes: 2

Related Questions