jrowen / rhandsontable

A htmlwidgets implementation of Handsontable.js
http://jrowen.github.io/rhandsontable/
Other
380 stars 147 forks source link

format = "0,0.0" not working when hot_cols applied with javascript renderer #403

Open brucefeiwang opened 2 years ago

brucefeiwang commented 2 years ago
MAT = matrix(runif(100, -1, 1), nrow = 10,
             dimnames = list(LETTERS[1:10], LETTERS[1:10]))
diag(MAT) = 1
MAT[upper.tri(MAT)] = MAT[lower.tri(MAT)]
rhandsontable(MAT, readOnly = TRUE, width = 750, height = 300) %>%
  hot_cols(renderer = "
           function (instance, td, row, col, prop, value, cellProperties) {
             Handsontable.renderers.TextRenderer.apply(this, arguments);if (value > 0.75) {
              td.style.background = 'lightgreen';
             }
           }") %>%
  hot_cols(fixedColumnsLeft = 3)%>%
  hot_col(1:2, format = "0,0.0")  #  **Not Working !!!**

last line not getting applied , due to the 'renderer' overwrite ?

zburch commented 2 years ago

I ran into the same problem. This can be solved in the renderer itself with very little JS knowledge...

MAT = matrix(runif(100, -1, 1), nrow = 10,
             dimnames = list(LETTERS[1:10], LETTERS[1:10]))
diag(MAT) = 1
MAT[upper.tri(MAT)] = MAT[lower.tri(MAT)]
rhandsontable(MAT, readOnly = TRUE, width = 750, height = 300) %>%
    hot_cols(renderer = "
           function (instance, td, row, col, prop, value, cellProperties) {
             Handsontable.renderers.TextRenderer.apply(this, arguments);
             if (value > 0.75) {
              td.style.background = 'lightgreen';
             }
             td.innerHTML = `${Number.parseFloat(value).toFixed(1)}`;
           }") %>%
    hot_cols(fixedColumnsLeft = 3)