How to refresh the vaadin Grid after you change something?
Asked Answered
L

1

0

I have a Vaadin grid that I use. I make a put request to update the scores of the elements in the grid. I was wondering how to make the grid respond after the update to show the new information. Right now I have to refresh the entire page to show the new information.

I'm not sure what code I would post, I'm using a basic vaadin grid if that helps.

Lillalillard answered 8/11, 2017 at 18:26 Comment(2)
Please put some code how you make a put request to update the scores of the elements in the grid. Which version of Vaadin?Afebrile
Similar Questions here (v8) and here (v7).Yuletide
F
0

I am not completely sure with what you mean by putting changes to the grid, but I suppose you are using setItems or a data provider?

For the first, you would have:

Grid<MyItem> grid = new Grid(MyItem.class);
grid.setItems(someItems);

While for the second you would write:

Grid<MyItem> grid = new Grid(MyItem.class);
grid.setDataProvider(...);

For the second way you can either specify the data provider using Java 8 notation as in:

grid.setDataProvider(
  (sortOrders, offset, limit) -> {//e.g. call to repo }, 
  () -> { // count provider, e.g. repo.count() });

or as in:

grid.setDataProvider(new ListDataProvider<>(myDataCollection));

To come to the question, in both cases you can call following to get the provider:

DataProvider<MyItem> provider = grid.getDataProvider();

To update one specific element, the data provider provides the method

provider.refreshItem(item);

Important to know is that the MyItem class has to implement a getId() method, or, alternatively, equals(). If this is not the case, you can invoke provider.refreshAll()

Fallacy answered 9/11, 2017 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.