I have an rhandsontable and I want the WHOLE ROW to be yellow if the cell in the text in the last column ("Comments") includes string "missed".
The code below highlights any cell that has a value 'missed', but not the whole row. Besides, I'd like the row to turn yellow when a cell in the last column CONTAINS "missed" - even inside a longer string, and not just when it contains only "missed" - as it is written now - I just don't know how to match strings in JavaScript.
DF = data.frame(a = 1:2, b = 3:4, Comments = c("missed etc", "missed"))
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 == 'missed') {
td.style.background = 'yellow' }
}")
Thank you very much!
To clarify, in reality, I am dealing with a larger table that I am rendering in rShiny. So, ideally the solution that works for the little data frame above should also work here. Currently it is not (nothing shows up at all):
output$session_table <- renderRHandsontable({
req(input$select_a_patient)
patient_nr <- which(patient_names_reactive$names %in% input$select_a_patient)
row_highlight = which(grepl("missed",
sessions_reactive$sessions[[patient_nr]]$Comments))-1
rhandsontable(sessions_reactive$sessions[[patient_nr]],
row_highlight = row_highlight,
width = 1000, height = 500) %>%
hot_rows(fixedRowsTop = 1) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_validate_numeric(cols = c(3, 5), min = 0, max = 500) %>%
hot_col(c(1, 3, 5, 6, 8), valign = 'htCenter') %>%
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 = 'yellow' }
}") %>% hot_col(c(5, 8), renderer = "
function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.style.fontWeight = 'bold';
td.style.color = '#fc0f03';}"
)