gpt4 book ai didi

javascript - 使用 rhandsontable 进行数字和条件格式设置

转载 作者:行者123 更新时间:2023-11-28 06:07:27 24 4
gpt4 key购买 nike

我发现我可以对 rhandonstable 进行数字格式化,或者对 rhandsontable 的样式进行条件格式化,但不能同时进行这两种操作。使用下面的代码,似乎只使用了代码的 javascript 部分。如果您能提供合并这两种格式类型的帮助,我将不胜感激。

DF = data.frame(int = 1:10, float = rnorm(10), cur = rnorm(10) * 1E5,
lrg = rnorm(10) * 1E8, pct = rnorm(10))

rhandsontable(DF, width = 550, height = 300) %>%
hot_cols(renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (row == 2){
td.style.background = 'lightyellow';
}}") %>%
hot_col("float", format = "0.0") %>%
hot_col("cur", format = "$0,0.00") %>%
hot_col("lrg", format = "0a") %>%
hot_col("pct", format = "0%")

最佳答案

您需要引用 NumericRenderer 而不是 TextRenderer

DF = data.frame(int = 1:10, float = rnorm(10), cur = rnorm(10) * 1E5,
lrg = rnorm(10) * 1E8, pct = rnorm(10))

rhandsontable(DF, width = 550, height = 300) %>%
hot_cols(renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.NumericRenderer.apply(this, arguments);
if (row == 2){
td.style.background = 'lightyellow';
}}") %>%
hot_col("float", format = "0.0") %>%
hot_col("cur", format = "$0,0.00") %>%
hot_col("lrg", format = "0a") %>%
hot_col("pct", format = "0%")

此处讨论问题 https://github.com/jrowen/rhandsontable/issues/45

关于javascript - 使用 rhandsontable 进行数字和条件格式设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36706586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com