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.select(item) does not highlight the newly selected row. #2031

Closed
masbaehr opened this issue Aug 27, 2018 · 5 comments
Closed

Grid.select(item) does not highlight the newly selected row. #2031

masbaehr opened this issue Aug 27, 2018 · 5 comments
Labels
Projects

Comments

@masbaehr
Copy link

If i select a row programmatically the row is not marked as selected

The select method i used is this:

Grid.select(item)

A row selection with the mouse marks the selected row in light-blue, but the programmatic (pre)selection does not highlight the selected row

image

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-grid-flow Oct 6, 2020
@vaadin-bot vaadin-bot added the flow label Oct 6, 2020
@web-padawan
Copy link
Member

Tested with the following example and could not reproduce:

Grid<String> grid = new Grid<>();
grid.addColumn(string -> string);
grid.setSelectionMode(SelectionMode.SINGLE);
grid.setItems("foo", "bar");
grid.select("foo");
add(grid);

Result:
Screenshot 2020-10-12 at 22 47 45

See also the examples of programmatic selection: https://vaadin.com/components/vaadin-grid/java-examples/selection

Closing as invalid.

@mikethomas77055
Copy link

@web-padawan
I'm also seeing this issue. I tried your example and it worked fine. However once I point the grid to an actual object (and not just the list of strings), that's where it breaks for me.

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.

@engor
Copy link

engor commented Jul 25, 2022

@mikethomas77055 did you solved it? It seems like items have different hashCode/equals results.
But I don't see the selection for the item being one of items of grid which equals by reference.
So I don't know what's wrong here.
Vaadin 14.8.13.

@mikethomas77055
Copy link

@engor
I ended up solving it by adding this to my AbstractEntity class (all of my entity classes extend AbstractEntity, so adding it to AbstractEntity solved this for all entities).

image

@engor
Copy link

engor commented Jul 25, 2022

@mikethomas77055 thanks for reply!
I found the reason of my issue - the Grid component works well, the reason was PaginatedGrid (I use it) which resets selection in it's onAttach event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
vaadin-core
  
📬  Inbox
Development

No branches or pull requests

5 participants