我正在努力根据单元格值在我的闪亮应用中为整行rhandsontable着色。
在下面的示例中,我想格式化整行而不是一个单元格。
library(rhandsontable)
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)
col_highlight = 2
row_highlight = c(5, 7)
rhandsontable(DF, width = 550, height = 300) %>%
hot_cols(renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if(value == 'F' | value == 'f') {
td.style.background = 'pink';
} else if(value == 'J' | value == 'j') {
td.style.background = 'lightgreen';
} else if(value == 'X' | value == 'x') {
td.style.background = 'lightblue'}
}")
答案 0 :(得分:3)
渲染器的概念是分别应用于所有单元格,因此同时单元格值不能是“F' F'并且' f'。对于每一行,您必须选择第2列以检查值是否为' F'并选择第3列以检查值是否为' f'。
rhandsontable(DF, width = 550, height = 300) %>%
hot_cols(renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if(instance.getData()[row][2] == 'F' | instance.getData()[row][3] == 'f'){
td.style.background = 'pink';
} else if(instance.getData()[row][2] == 'J' | instance.getData()[row][3] == 'j') {
td.style.background = 'lightgreen';
} else if(instance.getData()[row][2] == 'X' | instance.getData()[row][3] == 'x') {
td.style.background = 'lightblue'
}
}")