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.

Adam Horn
  • 1
  • 1
  • 1
    Please put some code how you _make a put request to update the scores of the elements in the grid_. Which version of Vaadin? – pirho Nov 09 '17 at 09:03
  • Similar Questions [here (v8)](https://stackoverflow.com/q/51871370/642706) and [here (v7)](https://stackoverflow.com/q/31861375/642706). – Basil Bourque Sep 19 '18 at 00:50

1 Answers1

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()

Stephan
  • 311
  • 1
  • 7