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

using grid.select(item) not highlighing or checking the item on the screen. #2086

Closed
mikethomas77055 opened this issue Nov 25, 2020 · 4 comments
Labels

Comments

@mikethomas77055
Copy link

I saw issue #2031 was closed recently as unable to reproduce, however I'm having the same issue. When I call grid.select(item) in code, the item is selected in memory, however it's not highlighted/checked on the screen. I've put some screenshots of a TestGrid class I wrote, a log entry showing that the item is in fact selected, and what I see in the UI. In the previous issue, the issue was closed and some sample code was provided showing it works as expected. I tried that sample code and it in fact worked as expected, however the sample code was populating the grid with a single column of strings. When I reworked that sample code to pull values from the database to populate the grid it stops working.

here's my code:
image

here's a screenshot of the log output:
image

here's a screenshot of what I see in the browser:
image

as you can see in the screenshots, other than me calling on my specific class to populate the grid, it's identical to yours. Also, based on the log output, it is "selecting" the first item fetched by default. However in the browser, no row is highlighted. I've greatly simplified this from what I'm trying to do for real. I'm actually working with a multi-select for real, but this appears to be the same issue regardless so I'm just using a single select here.

thanks for your help.

@tomivirkki
Copy link
Member

Hi @mikethomas77055

Tried with the following snippet, and for me the first items shows as selected just fine. Can you check if your SystemName class has errors in equals and hashCode implementations.

public TestGrid() {
    DepartmentData departmentData = new DepartmentData(2000);
    Grid<Department> grid = new Grid<Department>();
    grid.addColumn(Department::getName);
    grid.setSelectionMode(SelectionMode.SINGLE);
    grid.setItems(departmentData.getRootDepartments());
    Department item = departmentData.getRootDepartments().get(0);
    grid.select(item);
    add(grid);
    for (Department department : grid.getSelectedItems()) {
        System.out.println(department.getName());
    }
}

@tomivirkki tomivirkki added the waiting for author Further information is requested label Jan 28, 2021
@mikethomas77055
Copy link
Author

I don't have any errors in equals or hashCode.
your example showed selected in the UI? Can you send me your 'DepartmentData' class so I can try for myself?

thank you,
-Mike

@tomivirkki
Copy link
Member

tomivirkki commented Jan 28, 2021

Here's a copy-pasteable example:

public TestGrid() {
  List<Person> people = new ArrayList<>();
  people.add(new Person("Lucas"));
  people.add(new Person("Maria"));
  people.add(new Person("Hans"));

  Grid<Person> grid = new Grid<Person>();
  grid.addColumn(Person::getName);
  grid.setSelectionMode(SelectionMode.SINGLE);
  grid.setItems(people);
  Person item = people.get(0);
  grid.select(item);
  add(grid);
  for (Person person : grid.getSelectedItems()) {
    System.out.println(person.getName());
  }
}

class Person {
  private String name;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Person(String name) {
    this.name = name;
  }
}

Result, after opening the browser (using Vaadin 14.4.3 (also tried with V18)):

Screenshot 2021-01-28 at 17 48 32

@mikethomas77055
Copy link
Author

Thanks! I was able to figure it out based on what you sent me.

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

No branches or pull requests

3 participants