【发布时间】:2018-09-19 17:47:24
【问题描述】:
我正在尝试使用 rhandsontable 库来生成一个表,在该表中我结合了包的两个漂亮功能:(1) 使用客户 renderer 参数突出显示行,以及 (2) 复选框列类型一个布尔字段。
就其本身而言,这两个功能都可以正常工作。例如,下面显示了行突出显示的工作原理:
library(rhandsontable)
df = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
small = letters[1:10],
stringsAsFactors = FALSE)
row_highlight = c(5, 7)
rhandsontable(df,
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]
hrows = tbl.params.row_highlight
hrows = hrows instanceof Array ? hrows : [hrows]
if (hrows.includes(row)) {
td.style.background = 'pink';
}
return td;
}")
下面显示了复选框功能的工作原理:
library(rhandsontable)
df = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
small = letters[1:10],
stringsAsFactors = FALSE)
rhandsontable(df, row_highlight = row_highlight) %>%
hot_col(col = 'bool', type = 'checkbox')
我的问题:您如何结合这两个功能(即,生成一个带有突出显示的行和功能复选框的表格)?
有人会认为下面的方法可行,但复选框不会呈现(而是显示为 true 和 false):
library(rhandsontable)
df = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
small = letters[1:10],
stringsAsFactors = FALSE)
row_highlight = c(5, 7)
rhandsontable(df,
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]
hrows = tbl.params.row_highlight
hrows = hrows instanceof Array ? hrows : [hrows]
if (hrows.includes(row)) {
td.style.background = 'pink';
}
return td;
}") %>%
hot_col(col = 'bool', type = 'checkbox')
有没有办法在 R 的 rhandsontable 中结合复选框和行突出显示?
【问题讨论】:
标签: javascript r shiny handsontable rhandsontable