问题
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.
回答1:
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()
来源:https://stackoverflow.com/questions/47187072/how-to-refresh-the-vaadin-grid-after-you-change-something