rhandsontable icon indicating copy to clipboard operation
rhandsontable copied to clipboard

Conditional formatting and column removal

Open michaelhogersosis opened this issue 6 years ago • 2 comments

Hi there,

Thanks for this amazing package. I would like to ask if it is possible to both have editable/removable columns, while simultaneously applying formatting with the renderer.


           rhandsontable(current$current, col_highlight = col_highlight,
                          row_highlight = row_highlight, useTypes = FALSE, width = '100%') %>%
                          hot_context_menu(allowRowEdit = TRUE, allowColEdit = TRUE) %>%
                          hot_col(1, renderer =  "

           function (instance, td, row, col, prop, value, cellProperties) {
                          Handsontable.renderers.TextRenderer.apply(this, arguments);
                          td.style.background = 'green';
                          td.style.color = 'white';
                          
                          if (instance.params) {
                          hcols = instance.params.col_highlight
                          hcols = hcols instanceof Array ? hcols : [hcols]
                          hrows = instance.params.row_highlight
                          hrows = hrows instanceof Array ? hrows : [hrows]
                          }

                          if (instance.params && hrows.includes(row)){
                            td.style.background = 'red';
                            td.style.color = 'white';
                          }"
                    })


The renderer above breaks the possibility to edit the columns unfortunately.

michaelhogersosis avatar May 18 '18 13:05 michaelhogersosis

Could you please include the definition of the current variable.

jrowen avatar Jan 21 '19 17:01 jrowen

Hi @jrowen I would like to ask the same thing, could we trun useTypes to FALSE and formatting cells the same time? My code is similar

rhandsontable(t.df, useTypes = FALSE, row_highlight = 2) %>% 
                hot_context_menu(allowRowEdit = TRUE, allowColEdit = TRUE) %>% 
                hot_cols(renderer =  "function(instance, td, row, col, prop, value, cellProperties) {
                           Handsontable.renderers.TextRenderer.apply(this, arguments);
                           if (instance.params) {
                             hrows = instance.params.row_highlight
                             hrows = hrows instanceof Array ? hrows : [hrows] 
                           }
                           if (instance.params && hrows.includes(row)) td.style.background = 'pink';
                         }
                         ")

t.df can be any dataframe, e.g. t.df = data.frame(A=rep("a", 5), B=TRUE, C=1)

I think the problem is the TextRenderer, since TextRenderer=FALSE changed it not to be any JS type.

Could you give some clues how to make the change?

lz100 avatar Nov 12 '19 23:11 lz100