I want a way to color multiple cells in a data table if given their row and column indexes. I have found the solution from here. But here the function can colour only 1 cell. I want it to be modified, so that it takes a vector of row and column indexes as argument and colour them. Any help is highly appreciated. I am attaching the code snippet below.
changeCellColor <- function(row, col){
c(
"function(row, data, num, index){",
sprintf(" if(index == %d){", row-1),
sprintf(" $('td:eq(' + %d + ')', row)", col),
" .css({'background-color': 'orange'});",
" }",
"}"
)
}
datatable(iris,
options = list(
dom = "t",
rowCallback = JS(changeCellColor(1, 2))
)
)