html - GWT - 让 CellTable 单元格使用 HTML?

标签 html gwt cell

我有一个 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 中会忽略额外的空格 - 您应该使用 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();
        }
    };

关于html - GWT - 让 CellTable 单元格使用 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5801985/

相关文章:

swift - 为什么我的收藏 View 单元格颜色选择不起作用

html - 为什么将搜索输入放在表单标签中?

html - 超链接继承颜色,如何克服

java - GWT:本地化后托管模式错误

ios - 修改单元格 subview 的框架

mysql - 在 MySQL 中查找包含给定值的列

html - 为我的 ionic 2 应用程序更改 &lt;textarea&gt; 中占位符文本的颜色

javascript - 如何使用 html5 历史 API 阻止 <a> 标签加载新页面

gwt - 编辑后删除旧记录

html - 使用GWT和CSS,如何垂直翻转输入元素中偶数位置的所有字母?