【问题标题】:GWT - Make CellTable Cell use HTML?GWT - 使 CellTable Cell 使用 HTML?
【发布时间】:2011-08-13 16:55:31
【问题描述】:

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

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

我知道这可以使用 css 来完成,但我只想知道如何将 HTML 代码放入单元格中。任何帮助表示赞赏!

【问题讨论】:

    标签: html gwt cell


    【解决方案1】:

    AFAIK 额外的空格在 HTML 中被忽略 - 你应该使用 pre 标记来保持格式。无论如何,请在下面找到我的列示例。它根据数据提供者支持的对象中包含的值生成漂亮的进度条。

    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();
            }
        };
    

    【讨论】:

    • 感谢 jgrabowski!这很完美!是的,除非您使用 pre 标记,否则 html 中会忽略额外的空格。
    • 谢谢,这就是我要找的。​​span>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多