更改某些内容后如何刷新vaadin网格? [英] How to refresh the vaadin Grid after you change something?

查看:111
本文介绍了更改某些内容后如何刷新vaadin网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Vaadin网格可供使用.我发出放置请求以更新网格中元素的分数.我想知道如何在更新后使网格响应以显示新信息.现在,我必须刷新整个页面以显示新信息.

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.

我不确定要发布什么代码,如果有帮助,我正在使用基本的vaadin网格.

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

推荐答案

通过对网格进行更改,我不确定您的意思,但是我想您正在使用setItems还是数据提供程序?

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?

首先,您需要:

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

第二秒钟,您将编写:

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

第二种方法是,您可以使用Java 8表示法指定数据提供程序,如下所示:

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

或如下所示:

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

重要的是MyItem类必须实现getId()方法或equals().如果不是这种情况,则可以调用provider.refreshAll()

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

这篇关于更改某些内容后如何刷新vaadin网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆