问题描述
我正在使用 Vaadin 8.5.1 Grid 来显示 1000 行.一旦通过更改它的属性更新了一行,我使用grid.getDataProvider().refreshItem(selectedRow)或者grid.getDataProvider().refreshAll() 更新行失败.
我需要做显式的 grid.setItems() 来查看行的更新属性.
我正在使用下面的代码片段来创建一个网格
msgGrid = new ABSMsgGrid();列出<ConsoleEntry>messageEntryList = new 免费vpn ArrayList<>();如果(输入控制台!= null){messageEntryList.addAll(inputConsole.getMessageEntryList());}msgGridDataProvider vpn free = new ListDataProvider(messageEntryList) {@覆盖公共对象 getId(ConsoleEntry 项) {返回 item.getId();}};msgGrid.setDataProvider(msgGridDataProvider);//在更改网格行的属性时,我使用下面的代码片段私人无效句柄HideRowMenuItem(GridContextMenu contextMenu,ConsoleEntry selectedConsoleItem){if (!selectedConsoleItem.isHidden()) vpn free {hideRowMenuItem vpn free 免费vpn下载 = contextMenu.addItem("隐藏行", VaadinIcons.EYE_SLASH, selectedMenuItem -> {selectedConsoleItem.hide();**msgGridDataProvider.refreshItem(selectedConsoleItem);**}});}}公共类 ConsoleEntry {@覆盖公共布尔等于(对象 obj){//TODO 自动生成的方法存根if 免费vpn (obj instanceof ConsoleEntry) {ConsoleEntry temp = (ConsoleEntry) obj;字符串 msgRef2 = temp.getMsgRef();返回 this.getMsgRef().equalsIgnoreCase(msgRef2);}返回假;}@覆盖公共 int hashCode() {//TODO vpn free 自动生成的方法存根返回 super.hashCode();}公共字符串 getId(){返回 this.getMsgRef();}} 我见过类似的问题,但没有一个解决方案有效.
更改后如何刷新 vaadin Grid什么?
Vaadin - 行修改后刷新网格
如果有人可以分享如何解决这个问题的指针
TIA
要让一个项目被视为同一个项目,(并且刷新工作)你需要一个正确实现的 equals() 和对象上的 hashCode() 方法.
来自文档
<块引用>public void refreshItem(T vpn下载 item)
从接口复制的描述:DataProvider
刷新给定的项目.这种方法应该用于通知所有DataProviderListeners vpn下载 项目已被更新或替换为新实例.
要使其正常工作,该项目必须实现
equals( Object) 和 #hashCode() 认为旧项目实例和新项目实例相等,或者
DataProvider. getId( Object) 应该被实现以返回一个适当的标识符.
除此之外,您应该创建一个 ListDataProvider,将其分配给网格,然后通过先前分配的 ListDataProvider 免费vpn下载 的同一实例进行更新p>
I am using Vaadin 8.5.1 Grid to display 1000's of rows.
Once 免费vpn a row is updated with vpn 免费vpn free vpn下载 change in it property, I use
grid.getDataProvider().refreshItem(selectedRow)
or
grid.getDataProvider().refreshAll() which fails to update the row.
I need to do explicit grid.setItems() to see the updated property of the 免费vpn row.
I am using below snippet to create 免费vpn a Grid
msgGrid = new ABSMsgGrid();
List<ConsoleEntry> messageEntryList = new ArrayList<>();
if (inputConsole != null) 免费vpn下载 {
vpn下载 messageEntryList.addAll(inputConsole.getMessageEntryList());
}
msgGridDataProvider = new ListDataProvider<ConsoleEntry>(messageEntryList) {
@Override
vpn free public Object getId(ConsoleEntry item) {
免费vpn下载 return item.getId();
}
vpn 免费vpn free };
msgGrid.setDataProvider(msgGridDataProvider);
//on changing property of the grid row, i use the below snippet
private void free vpn vpn下载 handleHideRowMenuItem(GridContextMenu<ConsoleEntry> contextMenu, ConsoleEntry selectedConsoleItem) {
免费vpn vpn下载 if (!selectedConsoleItem.isHidden()) {
hideRowMenuItem 免费vpn下载 = contextMenu.addItem("Hide Row", VaadinIcons.EYE_SLASH, selectedMenuItem -> {
vpn下载 vpn free 免费vpn vpn下载 selectedConsoleItem.hide();
vpn free **msgGridDataProvider.refreshItem(selectedConsoleItem);**
}
});
}
}
public class ConsoleEntry {
免费vpn 免费vpn 免费vpn @Override
vpn下载 免费vpn下载 vpn下载 public boolean equals(Object obj) {
// TODO Auto-generated method stub
vpn free if (obj instanceof ConsoleEntry) {
免费vpn ConsoleEntry temp = (ConsoleEntry) vpn free obj;
免费vpn下载 vpn下载 String vpn free msgRef2 = temp.getMsgRef();
return this.getMsgRef().equalsIgnoreCase(msgRef2);
vpn下载 }
免费vpn 免费vpn下载 return vpn free false;
}
free vpn @Override
public int hashCode() {
// 免费vpn下载 TODO Auto-generated method stub
free vpn return super.hashCode();
}
vpn下载 免费vpn free vpn public String getId(){
vpn下载 免费vpn return this.getMsgRef();
}
}
I have seen similar question but none of the solutions worked.
How to refresh the vaadin Grid after vpn free you change something?
Vaadin - vpn free Refresh grid after row modification
Appreciate if any one could share free vpn pointers on how to solve this problem
TIA
For a item to be seen as the same item, (and the refresh working) you vpn free need a corretly implemented equals() and hashCode() methods on the object.
From the free vpn documentation
public void refreshItem(T item)
Description copied from interface: DataProvider
Refreshes the given item. This method should be used to inform all DataProviderListeners that an item has been updated or replaced with a new instance.
For this to work properly, the item must vpn下载 either free vpn implement
equals(Object) and #hashCode() to consider 免费vpn both the old and the new item instances to be equal, or 免费vpn alternatively
DataProvider.getId(Object) should be implemented to return 免费vpn an vpn下载 appropriate 免费vpn下载 identifier.
In addition to this, it's you should create a ListDataProvider, assign it to the grid and then do free vpn the updated via the same instance of the previously assigned ListDataProvider
这篇关于Vaadin 8.5.1- 行更新后刷新网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司免费vpn源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)