diff options
author | Tatu Lund <tatu@vaadin.com> | 2019-07-30 09:42:20 +0300 |
---|---|---|
committer | Zhe Sun <31067185+ZheSun88@users.noreply.github.com> | 2019-07-30 16:12:37 +0300 |
commit | 344d8660f3dbf9a0907b39c3260e8cf09c6462dc (patch) | |
tree | ffcdcfd9b692ce1bd27c4f784ab4833cdb52dda9 | |
parent | 1b5d3c06690a17f60fcbe4488ce53e8b922c90df (diff) | |
download | vaadin-framework-344d8660f3dbf9a0907b39c3260e8cf09c6462dc.tar.gz vaadin-framework-344d8660f3dbf9a0907b39c3260e8cf09c6462dc.zip |
Apply offset to column index depending on presense of selection column (#11667)
* Apply offset to column index depending on presense of selection column
After testing this manually I noticed that offset correction needs to be negative
* Add the testing UI
-rwxr-xr-x | client/src/main/java/com/vaadin/client/widgets/Grid.java | 6 | ||||
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnFrozenColumn.java | 67 |
2 files changed, 72 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 9f82d3339f..76fe46fbb7 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -7958,7 +7958,11 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, if (!event.getCell().isHeader()) { return; } - if (event.getCell().getColumnIndex() < getFrozenColumnCount()) { + int offset = 0; // apply offset depending on selection column, see #10546 + if (getSelectionColumn().isPresent()) { + offset = -1; + } + if (event.getCell().getColumnIndex()+offset < getFrozenColumnCount()) { return; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnFrozenColumn.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnFrozenColumn.java new file mode 100644 index 0000000000..057fbaa1da --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnFrozenColumn.java @@ -0,0 +1,67 @@ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ContentMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +public class GridColumnFrozenColumn extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new Label( + "Frozen columns can be reordered with unhidden columns with: " + + com.vaadin.shared.Version.getFullVersion())); + Label issueLabel = new Label( + "Demonstrate problem in <a href=\"https://github.com/vaadin/framework/issues/10546\">grid column frozen column reorder issue with SelectionMode.MULTI</a>"); + issueLabel.setContentMode(ContentMode.HTML); + layout.addComponent(issueLabel); + + // Create new Grid + Grid<HashMap<String, String>> grid = new Grid<>( + "My test grid to reorder columns"); + + // Fill the grid with data to sort + List<HashMap<String, String>> rows = new ArrayList<>(); + String FIRST = "Frozen Column (Should not be reordered)"; + String LAST = "Last Name Column"; + + // Grid for Vaadin 8 without bean class from + // https://vaadin.com/forum/#!/thread/16038356/16816582 + for (int i = 0; i < 20; i++) { + HashMap<String, String> fakeBean = new HashMap<>(); + fakeBean.put(FIRST, "first" + i); + fakeBean.put(LAST, "last" + i); + rows.add(fakeBean); + } + + grid.setItems(rows); + + // Add the columns based on the first row + HashMap<String, String> s = rows.get(0); + for (Map.Entry<String, String> entry : s.entrySet()) { + grid.addColumn(h -> h.get(entry.getKey())) + .setCaption(entry.getKey()).setId(entry.getKey()); + } + grid.getColumn(LAST).setHidable(true); + grid.setSelectionMode(Grid.SelectionMode.MULTI); + // without the selector column the issue cannot be observed + // grid.setSelectionMode(SelectionMode.NONE); + grid.setFrozenColumnCount(1); + grid.setColumnReorderingAllowed(true); + grid.setSizeFull(); + + layout.addComponent(grid); + layout.setMargin(true); + layout.setSpacing(true); + + addComponent(layout); + } +} |