GWT如何将自定义单元格添加到celltable / datagrid

时间:2012-06-29 20:34:32

标签: gwt datagrid cell custom-cell gwt-celltable

我已经渲染了一个自定义单元格,它结合了图像和文本。 它看起来像这样:

   class ImageTextCell extends AbstractCell<String> 

我的问题是如何将此单元格添加到celltable / datagrid中。 我已经厌倦了。

  Column<Message, String> iconColumn = new Column<Message, String>(new ImageTextCell())
            {
        @Override
        public String getValue(Message versionStatus) {

            return ? // I dont know what to type here. How to return the ImageTextCell object           }
    };

2 个答案:

答案 0 :(得分:11)

Cell对象的作用是将值转换为HTML。 Column的作用是从每一行获取该值。例如,您有一堆Messages,每个都在其自己的行上 - 列应该使用Message并找出要传递给String的{​​{1}}。

Cell的输出将输入getValue的输入。 render的输出应该是您要在应用中看到的HTML。

伪身体,这是GWT为你做的事情:

render

您只需要定义Column.getValue和Cell.render,以便此过程生成您想要的表。

答案 1 :(得分:0)

这是我在我的应用中显示png标志的方法:

  Column<IStationMini, ImageResource> flag = new Column<IStationMini, ImageResource>( new ImageResourceCell()) {
        @Override
        public ImageResource getValue(IStationMini station) {
            return FlagsTools.getFlag( station.getCountry());
        }
    };
this.addColumn( flag ) ;

“FlagsTools.getFlag()”返回一个imageResource

相关问题