GWT CellTable - 根据行添加列

发布于 2024-10-07 17:35:34 字数 122 浏览 0 评论 0原文

有谁知道是否可以根据显示行的某些值向 CellTable 添加一列?

通常使用 addColumn,但仅在 getValue 方法中启用对行属性的访问。我需要尽早获得此访问权限,以决定是向列添加一些值还是将其留空。

Does anybody know if this is possible to add a column to CellTable depending on the some value od displayed row?

Normally addColumn is used but the access to row properties is enabled only in getValue method. I need to gain this access earlier to decide either to add some value to column or lewave it blank.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

答案是编写自定义单元类来扩展适当的单元类(由 GWT 提供)。然后在渲染方法中,列的内容可能为空或不为空,具体取决于显示/渲染对象的值。例如

private class VersionCell<T> extends ActionCell<MovieDTO> {

    public VersionCell(String text, Delegate<MovieDTO> delegate) {
        super(text, delegate);
    }

    @Override
    public void render(MovieDTO m, Object key, SafeHtmlBuilder sb) {
        if (m != null && m.getId() != -1) {
            super.render(m, key, sb);
        } else if (m != null && m.getId() == -1) {
            sb.append(new SafeHtmlBuilder().appendHtmlConstant("").toSafeHtml());
        }
    }
}

The answer is to write custom cell class that extends the appropriate cell class (provided with GWT). Then in render method the column's content might be empty or not depending on the value of displayed/rendered object. E.g.

private class VersionCell<T> extends ActionCell<MovieDTO> {

    public VersionCell(String text, Delegate<MovieDTO> delegate) {
        super(text, delegate);
    }

    @Override
    public void render(MovieDTO m, Object key, SafeHtmlBuilder sb) {
        if (m != null && m.getId() != -1) {
            super.render(m, key, sb);
        } else if (m != null && m.getId() == -1) {
            sb.append(new SafeHtmlBuilder().appendHtmlConstant("").toSafeHtml());
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文