【问题标题】:GWT 2.4 CellTable issueGWT 2.4 CellTable 问题
【发布时间】:2011-11-28 13:05:06
【问题描述】:

从 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 中是否存在任何可能导致此问题的已知更改?谁能想到解决方法?

【问题讨论】:

    标签: java gwt


    【解决方案1】:

    您可以通过在单元格表的“thead”css 属性上使用 CSS 属性:“display: none”来实现相同的结果(隐藏标题)。

    方法如下:

    1.创建一个包含以下条目的 css 文件:

    Globalstyles.css:

        .hiddenHeader thead {
            display: none;
        }
    

    2。将此文件添加到客户端资源包:

    GlobalResources.java

        public interface GlobalResources extends ClientBundle {
            public static final GlobalResources RESOURCE =  GWT.create(GlobalResources.class);
    
            @Source("GlobalStyles.css")
            GlobalStylesheet styles();
    
        }
    

    3.在您的代码中,您可以在没有行时以编程方式设置样式:

        cellTable.addStyleName(GlobalResources.RESOURCE.styles().hiddenHeader());
    

    要删除样式,请调用:

        cellTable.removeStyleName(GlobalResources.RESOURCE.styles().hiddenHeader());
    

    完成!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多