0

how do I modify the code in this thread here to apply the color format to the entire row, not just a particular cell?

Particularly, this one:

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(dat, 
          options = list(
            dom = "t",
            rowCallback = JS(changeCellColor(1, 2))
          )
)

Thanks,

Tristan Tran
  • 1,351
  • 1
  • 10
  • 36

1 Answers1

1

Here you go:

changeCellColor <- function(row){
  c(
    "function(row, data, num, index){",
    sprintf("  if(index == %d){", row-1),
    "for(n = 0; n <= 4; n++) {",
    "  $('td:eq(' + n + ')', row)",
    "    .css({'background-color': 'orange'});",
    "}",
    "  }",
    "}"  
  )
}
datatable(dat, 
          options = list(
            dom = "t",
            rowCallback = JS(changeCellColor(1))
          )
)
mosk915
  • 696
  • 1
  • 7
  • 16