【问题标题】:Numeric and Conditional Formatting with rhandsontablerhandsontable 的数值和条件格式
【发布时间】:2016-08-10 22:26:36
【问题描述】:

我发现我可以对 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%")

【问题讨论】:

    标签: javascript r formatting handsontable


    【解决方案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

    【讨论】:

      猜你喜欢
      • 2018-07-08
      • 2020-03-03
      • 2020-12-02
      • 2020-12-15
      • 2020-12-03
      • 2020-01-07
      • 2017-12-02
      • 2019-07-15
      • 1970-01-01
      相关资源
      最近更新 更多