GWT - 使CellTable Cell使用HTML? [英] GWT - Make CellTable Cell use HTML?

查看:120
本文介绍了GWT - 使CellTable Cell使用HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CellTable,我想把HTML代码放在单元格中。
以下代码不起作用,空格将从输出中删除。

I have a CellTable where I want to put HTML-code in the cells. The following code is not working, the blank spaces are removed from the output.

    TextColumn<MyCell> column1 = new TextColumn<MyCell>()
    {
        @Override
        public String getValue(MyCell myCell)
        {
            String result = "     " +myCell.getValue();
            return result;
        }
    };
    table.addColumn(column1 , "Header1");

我知道这可以使用css完成,但我只想知道如何将HTML代码放入细胞。任何帮助感激!

I know this could be done using css but I just want to know how to put HTML-code in the cells. Any help is appreciated!

推荐答案

AFAIK额外的空格在HTML中被忽略 - 您应该使用pre标签来保持格式化。任何方式请查找我的列示例如下。它通过数据提供者支持的对象中包含的值生成良好的进度条。

AFAIK additional whitespace is ignored in HTML - you should use pre tag to maintain formatting.Anyway please find my column sample below. It generates nice progress bar from values contained in objects backed by data provider.

final SafeHtmlCell progressCell = new SafeHtmlCell();

    Column<UiScheduledTask, SafeHtml> progressCol = new Column<UiScheduledTask, SafeHtml>(
            progressCell) {

        @Override
        public SafeHtml getValue(UiScheduledTask value) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            float percent = new Float(value.getCompleted())
                    / new Float(value.getAll());
            int rounded = Math.round(percent * 100);
            sb.appendHtmlConstant("<div style='width: 100px; height: 20px; position: relative;'>");
            sb.appendHtmlConstant("<div style='z-index: 2; display: inline; width: 100px; position: absolute; left: 0px, top: 0px; text-align: center;'>"
                    + value.getCompleted()
                    + "/"
                    + value.getAll()
                    + "</div>");
            sb.appendHtmlConstant("<div style='position: absolute; left: 0; top: 0; width: 100px; z-index: 1'><div style='display: inline; float: left; width: "
                    + rounded
                    + "%; height: 20px; background-color: #82cd80;'></div>");
            sb.appendHtmlConstant("<div style='display: inline; float: right; width: "
                    + (100 - rounded)
                    + "%; height: 20px; background-color: #c54c4d;'></div></div>");
            sb.appendHtmlConstant("</div>");
            return sb.toSafeHtml();
        }
    };

这篇关于GWT - 使CellTable Cell使用HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆