【问题标题】:GWT Determining Row Value during Cell renderGWT 在单元格渲染期间确定行值
【发布时间】:2012-06-26 15:27:11
【问题描述】:

我想根据 CellTable(或 DataGrid)中“行”值的值来确定是否使用图标。在构建 Cell 渲染器时如何确定?

IconCellDecorator<String> icd = new IconCellDecorator<String>(res.search(), new ClickableTextCell()) {
  @Override
  protected boolean isIconUsed(String value) {
    //value may not be unique across rows (column value), I really need the row instance here.
  }
};

【问题讨论】:

  • 在我看来,我真的希望装饰器采用我的行类型,但是 ClickableTextCell 不知道如何获取它需要的字符串值。看来我必须编写一个自定义 IconCellDecorator,但认为可能有更清洁的解决方案。
  • 刚刚意识到 render() 有一个提供索引和键的上下文......认为这可能会有所帮助。

标签: gwt datagrid render cell celltable


【解决方案1】:

如果您需要 row 对象,则必须使用 IconCellDecorator&lt;RowObject&gt;,并将 ClickableTextCell 包装或子类化以从 RowObject 中提取 String

或者您可以使用CompositeCellImageResourceCell 而不是IconCellDecorator

【讨论】:

  • 包装/子类化 ClickableTextCell 看起来很尴尬。它并不是真的要处理非文本。我会看看 CompositeCell 是否有意义。 (我实际上已经制作了自己的 IconDecorator,它在不使用图标时不会显示空白区域。因此可能需要重构)
【解决方案2】:

我决定重写 IconCellDecorator 以便 getImageUsed 方法传入 Context 对象,它为我提供行索引和键。这似乎是我想要完成的最直接的目标,尽管 Thomas 的回答也应该有效。

【讨论】:

    猜你喜欢
    • 2010-11-05
    • 2019-07-16
    • 2015-03-21
    • 2015-01-01
    • 2019-01-13
    • 2012-02-16
    • 1970-01-01
    • 2016-05-18
    • 2011-10-02
    相关资源
    最近更新 更多