简体   繁体   中英

Numeric and Conditional Formatting with rhandsontable

I'm finding that I can either numerically format the rhandonstable or conditionally format the style of the rhandsontable, but not both. Using the following code, it seems that only the javascript portion of the code is being used. I'd greatly appreciate any help to incorporate both formatting types.

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%")

You need to reference NumericRenderer rather than 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%")

Issue is discussed here https://github.com/jrowen/rhandsontable/issues/45

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM