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.

GridColumnFrozenColumn.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.vaadin.tests.components.grid;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import com.vaadin.server.VaadinRequest;
  7. import com.vaadin.shared.ui.ContentMode;
  8. import com.vaadin.tests.components.AbstractTestUI;
  9. import com.vaadin.ui.Grid;
  10. import com.vaadin.ui.Label;
  11. import com.vaadin.ui.VerticalLayout;
  12. public class GridColumnFrozenColumn extends AbstractTestUI {
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. final VerticalLayout layout = new VerticalLayout();
  16. layout.addComponent(new Label(
  17. "Frozen columns can be reordered with unhidden columns with: "
  18. + com.vaadin.shared.Version.getFullVersion()));
  19. Label issueLabel = new Label(
  20. "Demonstrate problem in <a href=\"https://github.com/vaadin/framework/issues/10546\">grid column frozen column reorder issue with SelectionMode.MULTI</a>");
  21. issueLabel.setContentMode(ContentMode.HTML);
  22. layout.addComponent(issueLabel);
  23. // Create new Grid
  24. Grid<HashMap<String, String>> grid = new Grid<>(
  25. "My test grid to reorder columns");
  26. // Fill the grid with data to sort
  27. List<HashMap<String, String>> rows = new ArrayList<>();
  28. String FIRST = "Frozen Column (Should not be reordered)";
  29. String LAST = "Last Name Column";
  30. // Grid for Vaadin 8 without bean class from
  31. // https://vaadin.com/forum/#!/thread/16038356/16816582
  32. for (int i = 0; i < 20; i++) {
  33. HashMap<String, String> fakeBean = new HashMap<>();
  34. fakeBean.put(FIRST, "first" + i);
  35. fakeBean.put(LAST, "last" + i);
  36. rows.add(fakeBean);
  37. }
  38. grid.setItems(rows);
  39. // Add the columns based on the first row
  40. HashMap<String, String> s = rows.get(0);
  41. for (Map.Entry<String, String> entry : s.entrySet()) {
  42. grid.addColumn(h -> h.get(entry.getKey()))
  43. .setCaption(entry.getKey()).setId(entry.getKey());
  44. }
  45. grid.getColumn(LAST).setHidable(true);
  46. grid.setSelectionMode(Grid.SelectionMode.MULTI);
  47. // without the selector column the issue cannot be observed
  48. // grid.setSelectionMode(SelectionMode.NONE);
  49. grid.setFrozenColumnCount(1);
  50. grid.setColumnReorderingAllowed(true);
  51. grid.setSizeFull();
  52. layout.addComponent(grid);
  53. layout.setMargin(true);
  54. layout.setSpacing(true);
  55. addComponent(layout);
  56. }
  57. }