Samantha S
Samantha S

Reputation: 21

Numeric and Conditional Formatting with rhandsontable

I'm finding that I can either numerically format the rhandsontable 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%")

Upvotes: 2

Views: 2065

Answers (1)

Will
Will

Reputation: 23

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

Upvotes: 1

Related Questions