You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridScrollDestination.java 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. package com.vaadin.tests.components.grid;
  2. import java.util.Arrays;
  3. import java.util.stream.IntStream;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.shared.ui.grid.ScrollDestination;
  6. import com.vaadin.tests.components.AbstractTestUI;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.Grid;
  9. import com.vaadin.ui.NativeSelect;
  10. import com.vaadin.ui.TextField;
  11. public class GridScrollDestination extends AbstractTestUI {
  12. @Override
  13. protected void setup(VaadinRequest request) {
  14. Grid<Integer> grid = new Grid<>();
  15. grid.addColumn(Integer::intValue).setCaption("number");
  16. grid.setItems(IntStream.range(0, 100).boxed());
  17. TextField tf = new TextField("row index", "50");
  18. NativeSelect<ScrollDestination> ns = new NativeSelect<>(
  19. "scroll destination",
  20. Arrays.asList(ScrollDestination.values()));
  21. ns.setValue(ScrollDestination.ANY);
  22. Button button = new Button("Scroll to above row index", (event) -> {
  23. int rowIndex = Integer.parseInt(tf.getValue());
  24. grid.scrollTo(rowIndex, ns.getValue());
  25. });
  26. addComponents(tf, ns, button, grid);
  27. }
  28. }