Refresh a Grid

I need to refresh my Grid from database in some points of my code.
I didn’t find any way to do it.
Is there any way to force data refresh in my grid by code ?
Tks
Tullio

Put your Databasecall in a method and call it where you need to refresh the grid data or do i miss something?

May be I missed something.
What I need is to adjust my grid informations when the undelying db changes.
Then I need to say to the grid “refresh yourself reading the underlyng db”.
Tks

Something like:

grid.getDataProvider().refreshAll();

?

It doesn’t matter what you feed your grid with. It always becomes a data provider.
That data provider must be notified.

Done but it simply doesn’t work.
No access to the underlying db.

It depends on how you read from the database. If you extract information and put it into a list, a simple refreshAll does not work, because the list itself does not contain the changed values. Instead you have to reread from the database into a new List and then call setItems again.

If you implement a data provider and inside that data provider the database is read, refreshAll() must be called to start the data update.

In your case (reading from a database), the last one should be preferred.

Sorry but I still don’t understand.
If I force the DataProvider to requery data how can I force Grid to repaint ?
Tks

Tullio Bettinazzi:
Sorry but I still don’t understand.
If I force the DataProvider to requery data how can I force Grid to repaint ?
Tks

The grid should automatically repaint. If you are in a background thread (no Vaadin originated UI thread) you have to use Push: https://vaadin.com/docs/v14/flow/advanced/tutorial-push-access.html

If this answer is not sufficient for you, it would be helpful if you posted some example code.

Thank you

Tks for Your help.
I work in the Vaadin Thread.
I do in my data provider :
@Override
public void refreshAll() {
findAllDefaultQuery();
super.refreshAll();
}

where findAllDefaultQuery() executes the query and then I execute the super.refreshAll().
When I need to refresh I call the refresh all of the DataProvider.
But the DataComunicator doesn’t seem to be aware that data changed.
My data provider doesn’t have any cache nor any List.
What I missed ?
Tks

refreshAll() should not be overriden.

See: https://vaadin.com/docs/v14/flow/binding-data/tutorial-flow-data-provider.html
on how to implement a DataProvider.

You just use:
DataProvider.fromCallbacks(…

and implement the first argument as a fetch for all items based on a query (including things like filter, offset and limit).
The second argument must return the number of all available items (including filter).