Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid is not refreshed correctly after Multi-Selection with SHIFT #42

Open
finaris-cs opened this issue Jul 19, 2023 · 2 comments
Open

Comments

@finaris-cs
Copy link

finaris-cs commented Jul 19, 2023

Affected Version: 3.0.1 / Vaadin 24.0

  1. Select the first row
  2. Hold SHIFT down and select the 4th row
  3. Click on 5th row without any modifier keys

=> The first row remains visually selected even though its is not selected according to model or selection event (see status line in example below grid)
The code below can be used for reproduction.
Calling a refreshAll() on the grid's data provider can be used as workaround to let the wrong selection disappear

My expectation would be that the grid handles this internally.

image

package com.finaris.sqace.frontend.ui.views;

import com.vaadin.componentfactory.selectiongrid.SelectionGrid;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;

import java.util.*;
import java.util.stream.Collectors;

@Route(value = "test3")
public class TestView3 extends VerticalLayout {

//    private Set<Item> lastSelection = Collections.emptySet();

    public TestView3() {
        List<Item> itemList = new ArrayList<>();
        itemList.add(new Item(1, "Carl", "Allisson"));
        itemList.add(new Item(2, "Margot", "Fine"));
        itemList.add(new Item(3, "Christian", "Black"));
        itemList.add(new Item(4, "Tom", "Greene"));
        itemList.add(new Item(5, "Anna", "Smith"));
        itemList.add(new Item(6, "Ashley", "Parker"));
        itemList.add(new Item(7, "Greg", "van Helsing"));
        itemList.add(new Item(8, "Michael", "Washington"));
        itemList.add(new Item(9, "Hanna", "Walker"));
        itemList.add(new Item(10, "Anthony", "King"));
        setSizeFull();
        Grid<Item> grid = new SelectionGrid<>();
        grid.setSizeFull();
        grid.setSelectionMode(Grid.SelectionMode.MULTI);

        grid.addColumn(Item::getId).setHeader("ID");
        grid.addColumn(Item::getFirstName).setHeader("First Name");
        grid.addColumn(Item::getLastName)
                .setHeader("Last Name");
        grid.setItems(itemList);

        Span info = new Span();
        grid.addSelectionListener(e -> {
            Set<Item> allSelectedItems = e.getAllSelectedItems();
            info.setText("Selection according to model: " + allSelectedItems.stream().map(Object::toString).collect(Collectors.joining(", ")));

//            if (allSelectedItems.size() < lastSelection.size()) {
//                grid.getDataProvider().refreshAll();
//            }
//            lastSelection = allSelectedItems;
        });
        add(grid, info);
    }


    private static class Item {
        private final int id;
        private final String firstName;
        private final String lastName;

        public Item(int id, String firstName, String lastName) {
            this.id = id;
            this.firstName = firstName;
            this.lastName = lastName;
        }

        @Override
        public String toString() {
            return firstName + " " + lastName;
        }

        public int getId() {
            return id;
        }

        public String getFirstName() {
            return firstName;
        }

        public String getLastName() {
            return lastName;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Item item = (Item) o;
            return Objects.equals(id, item.id);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id);
        }
    }
}

@paodb
Copy link

paodb commented Jul 19, 2023

Which exact Vaadin version are you using? This issue was introduced by some changes on Vaadin Grid in vaadin/flow-components#4902 but it was reverted in Vaadin 24.0.6.

@finaris-cs
Copy link
Author

24.0.5, i will upgrade then, ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants