GWT替代细胞

时间:2014-06-06 05:37:33

标签: java gwt gwt2 gwt-celltable

如何在GWT CellsColumns处选择创建Cell Table? 例如:我有一列,偶数行会显示Button Cells奇数行会显示Text Cells。 有可能吗?如果是的话,我怎么能搞清楚?谢谢你的任何建议!

下图是一个例子......

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以构建custom cell,根据其上下文显示不同的内容:

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    if (context.getIndex() & 1 == 0) {
        // render one way
    } else {
        // render the other way
    }
}

答案 1 :(得分:0)

谢谢先生@AndreiVolgin。现在我明白了。这是我的代码,作为先生 Andrei Volgin 的答案。

        ButtonCell buttonCellEdit = new ButtonCell() {
        @Override
        public void render(final Context context, final SafeHtml data, final SafeHtmlBuilder sb) {
            if (i++ % 2 == 0) {
                sb.appendHtmlConstant("It is row " + i);
            }
            else {
                sb.appendHtmlConstant("<button type=\"button\" class=\"gwt-Button btn btnBlue\" tabindex=\"-1\">");
                if (data != null) {
                    sb.append(data);
                }
                sb.appendHtmlConstant("</button>");
            }
        }
    };