GWT 2.4 CellTable 问题
从 GWT 2.3 升级到 2.4 导致我的一个扩展 CellTable 的类出现客户端异常。功能并没有损失,但例外的是持续的开发烦恼。
com.google.gwt.core.client.JavaScriptException: (TypeError): this.insertBefore 不是一个函数
我已经确定了导致此问题的行,尽管在稍后渲染表之前不会引发异常。在行更改处理程序中,当 CellTable 中没有行时,MyCellTable 会删除标题元素。下面是一些在 2.4 中导致异常但在 2.3 中不会导致异常的示例代码。
CellTable<String> table = new CellTable<String>();
table.addColumn(new TextColumn<String>() {
@Override
public String getValue(String object) {
return object;
}
}, "Col");
List<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
table.setRowData(list);
NodeList<Element> els = table.getElement().getElementsByTagName("THEAD");
if (els.getLength() == 0) {
return;
}
final Element e = els.getItem(0);
e.removeFromParent();
降级到 GWT 2.3 可以解决该问题。我尝试调用 headerElement.setAttribute("style", "display: none") 而不是删除该元素,但这看起来不一样(它仍然保留了一些像素)。我知道创建一个 CellTable 然后删除它的一部分可能是一个不好的做法。
GWT 2.4 中是否有任何已知的更改可能导致此问题?有人能想到解决方法吗?
Upgrading from GWT 2.3 to 2.4 caused a client-side exception in a class of mine that extends CellTable. There has been no loss of functionality, but the exception is a constant development annoyance.
com.google.gwt.core.client.JavaScriptException: (TypeError): this.insertBefore is not a function
I’ve identified the line that causes this, though the exception doesn't get thrown until the table is rendering later. In a row change handler, MyCellTable removes the header Element when there are no rows in the CellTable. Here's some example code that causes the exception in 2.4, but not in 2.3.
CellTable<String> table = new CellTable<String>();
table.addColumn(new TextColumn<String>() {
@Override
public String getValue(String object) {
return object;
}
}, "Col");
List<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
table.setRowData(list);
NodeList<Element> els = table.getElement().getElementsByTagName("THEAD");
if (els.getLength() == 0) {
return;
}
final Element e = els.getItem(0);
e.removeFromParent();
Downgrading to GWT 2.3 fixes the problem. I tried calling headerElement.setAttribute("style", "display: none") instead of removing the element, but that doesn't look the same (it still keeps a few pixels there). I'm aware that creating a CellTable and then ripping out pieces of it is probably a bad practice.
Are there any known changes in GWT 2.4 that could be causing this problem? Can anyone think of a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过使用单元格表的“thead”css 属性上的 CSS 属性:“display: none”来实现相同的结果(隐藏标题)。
方法如下:
1.创建一个 css 文件,其中包含以下条目:
Globalstyles.css:
2。将此文件添加到客户端资源包:
GlobalResources.java
3.在您的代码中,您可以在没有行时以编程方式设置样式:
要删除样式,请调用以下命令:
完成!
You can achieve the same result (hiding the header) by using the CSS property: "display: none" on the "thead" css attribute of the celltable.
Here's how:
1. Create a css file with the following entry in it:
Globalstyles.css:
2. Add this file to a client resource bundle:
GlobalResources.java
3. In your code, you can programatically set the style when there are no rows:
And to remove the style call this:
Done!