Tullio
(Tullio Bettinazzi)
August 5, 2020, 10:34am
1
When I refresh my grid from code I need to select the first (or another) item.
However if I do this just after my refreshAll() it doesn’t work :data are not yet read from the DB.
After a while, I suspect in an asynchronous way, data are read but I didn’t find any possibility to select the required item.
Is it possible ? How ?
Tks
virkki
(Tomi Virkki)
August 6, 2020, 7:06am
2
Hi, tried with the following and it worked fine:
add(new Button("Refresh and select", e -> {
grid.getDataProvider().refreshAll();
grid.select(people.get(0));
}));
Please provide a code example that reproduces the issue so we can take a better look.
Also, make sure that your items have equals/hashCode properly implemented. If not, selection (and many other things) might not work as you’d expect.
Tullio
(Tullio Bettinazzi)
August 6, 2020, 9:23am
3
Sorry what’s peole in Your example ?
My data comes from DB, I’ve no array of data in memory.
Tks
virkki
(Tomi Virkki)
August 6, 2020, 2:08pm
4
Sorry what’s peole in Your example ?
It’s the Person bean from https://vaadin.com/components/vaadin-grid/java-examples
Tullio
(Tullio Bettinazzi)
August 6, 2020, 2:14pm
5
I understand but where can I find it ?
How can I ask the grid : tell me what’s Your first item ?
I’m not using any listed data provider but a data provider getting data from a database.
Tks
Tullio
(Tullio Bettinazzi)
August 6, 2020, 4:52pm
6
Anyway I tested your solution without a button and I found a problem : when refresh is executed showing the page for the first time data are not already loaded and then I’ve not the first row.
Tks