使用rhandsontable进行数字和条件格式化

问题描述 投票:0回答:1

我发现我可以对 rhandsontable 进行数字格式化,也可以对 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%")
javascript r formatting rhandsontable
1个回答
1
投票

您需要引用 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

© www.soinside.com 2019 - 2024. All rights reserved.