在 rhandsontable() 中添加自定义渲染器会删除类型显示

问题描述

显示类型的 rhandsontable 中添加 hot_cols(renderer = "...") 删除它们。

有没有办法指定自定义渲染器并保留“类型”?

DF = data.frame(val = 1:10,bool = TRUE,big = LETTERS[1:10],small = letters[1:10],dt = seq(from = Sys.Date(),by = "days",length.out = 10),stringsAsFactors = FALSE)

# display Types properly:
rhandsontable(DF)

# Does not:
col_highlight = 2
row_highlight = c(5,7)
rhandsontable(DF,col_highlight = col_highlight,row_highlight = row_highlight) %>%
  hot_cols(renderer = "
    function(instance,td,row,col,prop,value,cellProperties) {
      Handsontable.renderers.TextRenderer.apply(this,arguments);      
      tbl = this.HTMLWidgets.widgets[0]
      hcols = tbl.params.col_highlight
      hcols = hcols instanceof Array ? hcols : [hcols] 
      hrows = tbl.params.row_highlight
      hrows = hrows instanceof Array ? hrows : [hrows] 
      if (hcols.includes(col) && hrows.includes(row)) {
        td.style.background = 'red';
      }
      else if (hcols.includes(col)) {
        td.style.background = 'lightgreen';
      }
      else if (hrows.includes(row)) {
        td.style.background = 'pink';
      }      
      return td;
  }")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)