vaadin-component-factory / selection-grid-flow

Add the functionality to Vaadin Grid to focus on a particular row and column and select a range of rows with SHIFT/CTRL Click
https://incubator.app.fi/selection-grid-flow-demo/
Apache License 2.0
5 stars 8 forks source link

Multi selection (checkbox) column is shown on reattach #21

Closed stefanuebe closed 3 years ago

stefanuebe commented 3 years ago

The SelectionGrid has an executeJS call to hide the multi selection column, which is called in the constructor. When detaching and reattaching the SG, the column is shown again. To fix that, the JS call should be moved from the constructor to the onAttach method of the grid (or an internal AttachListener).

Reproducible example

Simple detach and reattach the Grid using the button.

@Route(value = "selection-grid-issue")
public class SelectionGridIssueView extends Div {

    public SelectionGridIssueView() {
        setSizeFull();

        List<SamplePerson> persons = new ArrayList<>();

        persons.add(new SamplePerson("Henry"));
        persons.add(new SamplePerson("Indiana"));
        persons.add(new SamplePerson("Jones"));

        SelectionGrid<SamplePerson> grid = new SelectionGrid<>();
        grid.setItems(persons);
        grid.setSelectionMode(Grid.SelectionMode.MULTI);

        grid.addColumn(SamplePerson::getName)
                .setHeader("Name");

        add(new Button("Detach/Reattach", event -> {
            if (grid.getParent().isPresent()) {
                remove(grid);
            } else {
                add(grid);
            }
        }), grid);
    }

    public static class SamplePerson {
        private final String name;
        public SamplePerson(String name) {
            this.name = name;
        }
        public String getName() {
            return name;
        }
    }
}

Workaround

Call the JS manually using an attach listener.

SelectionGrid<> grid = // ... create grid;
grid.addAttachListener(event -> {
    grid.getElement().executeJs("if (this.querySelector('vaadin-grid-flow-selection-column')) { " +
            "this.querySelector('vaadin-grid-flow-selection-column').hidden = true; " +
            "}");
});
jcgueriaud1 commented 3 years ago

Closed by #22 Released in v0.4.2

huber-and commented 3 years ago

Same issue for SelectionTreeGrid, can you please provide the same fix?

jcgueriaud1 commented 3 years ago

Yes, thanks for noticing it. It's fixed in v0.4.3.