【问题标题】:Format cell text color格式化单元格文本颜色
【发布时间】:2018-10-05 23:41:36
【问题描述】:

此列格式化程序可以很好地设置背景颜色,但是我根本看不到文本。

function truthFormatter(cell, formatterParams, onRendered) {
    var cellValue = cell.getValue();
    var cellElement = cell.getElement();
    if (cellValue == "T") {
    cellElement.style.backgroundColor = "#0000B3";
    cellElement.style.color = "#FFFFFF";
    }
    else if (cellValue == "F") {
    cellElement.style.backgroundColor = "#B30000";
    cellElement.style.color = "#FFFFFF";
    }
}

其中一个单元格上的 Chrome 样式检查器表明一切都应该没问题:

element.style {
    width: 40px;
    text-align: center;
    background-color: rgb(0, 0, 179);
    color: rgb(255, 255, 255);
    height: 25px;
}

我在独立的测试配置中得到了相同的行为——没有应用其他 CSS。

此外,不应应用格式化程序的单元格中的文本不可见——尽管此处的样式检查似乎也很好:

element.style {
    width: 151px;
    text-align: right;
    color: rgb(0, 0, 0);
    height: 32px;
}

Link to screenshot of table as rendered

Link to rendering without the formatter

【问题讨论】:

    标签: javascript tabulator


    【解决方案1】:

    你的行:

    cellElement.style.color = "#FFFFFF";
    

    应该可以正常工作,我已经运行了一些测试并且它可以工作。

    我建议使用您的浏览器检查器来查看覆盖它的 CSS。

    您也没有在格式化程序中返回单元格的值,因此单元格内不会显示任何内容。

    您需要将此行添加到格式化程序函数的底部

    return cell.getValue();
    

    【讨论】:

    • 这似乎不是问题所在。请看我提炼的问题。
    • 你能发一张你桌子的截图吗
    • 添加了截图链接。
    • 问题不在于您的文本颜色错误,而在于它根本不存在,您没有从格式化程序返回单元格值。我已经更新了我的答案来解释如何做到这一点
    猜你喜欢
    • 2019-09-30
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 2015-11-12
    • 2013-10-18
    • 1970-01-01
    相关资源
    最近更新 更多