How to refresh the vaadin Grid after you change something?

。_饼干妹妹 提交于 2019-12-14 03:04:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!