簡體   English   中英

使用rhandsontable進行數字和條件格式化

[英]Numeric and Conditional Formatting with rhandsontable

我發現我可以在數字上格式化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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM