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.

HideGridColumnWhenHavingUnsuitableHeight.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.vaadin.tests.components.grid;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.vaadin.annotations.Theme;
  5. import com.vaadin.annotations.Widgetset;
  6. import com.vaadin.server.VaadinRequest;
  7. import com.vaadin.tests.components.AbstractTestUI;
  8. import com.vaadin.ui.Grid;
  9. import com.vaadin.ui.renderers.ButtonRenderer;
  10. @Theme("valo")
  11. @Widgetset("com.vaadin.DefaultWidgetSet")
  12. public class HideGridColumnWhenHavingUnsuitableHeight extends AbstractTestUI {
  13. private Grid<SampleBean> grid;
  14. public static class SampleBean {
  15. private String col1;
  16. private String col2;
  17. public SampleBean() {
  18. }
  19. public String getCol1() {
  20. return col1;
  21. }
  22. public void setCol1(String col1) {
  23. this.col1 = col1;
  24. }
  25. public String getCol2() {
  26. return col2;
  27. }
  28. public void setCol2(String col2) {
  29. this.col2 = col2;
  30. }
  31. }
  32. @Override
  33. protected void setup(VaadinRequest vaadinRequest) {
  34. grid = new Grid<>();
  35. grid.setItems(generateData(50));
  36. grid.addColumn(SampleBean::getCol1).setWidth(1600);
  37. grid.addColumn(SampleBean::getCol2);
  38. grid.addColumn(t -> "Button1").setRenderer(new ButtonRenderer<>());
  39. grid.getColumns().forEach(c -> c.setHidable(true));
  40. grid.setWidth("100%");
  41. grid.setHeight("425px");
  42. addComponent(grid);
  43. }
  44. private List<SampleBean> generateData(int rows) {
  45. List<SampleBean> list = new ArrayList<>();
  46. for (int y = 0; y < rows; ++y) {
  47. SampleBean sampleBean = new SampleBean();
  48. sampleBean.setCol1("Row " + y + " Column 1");
  49. sampleBean.setCol2("Row " + y + " Column 2");
  50. list.add(sampleBean);
  51. }
  52. return list;
  53. }
  54. }