Format groupby rows in reactable

98 Views Asked by At

In reactable, is there a way to style the entire row of groupBy header? e.g. to add a border to the bottom like this:

enter image description here

Code for table:

library(reactable)

data <- MASS::Cars93[10:22, c("Manufacturer", "Model", "Type", "Price", "MPG.city")]

reactable(
  data,
  groupBy = "Manufacturer",
  defaultExpanded = TRUE
)
1

There are 1 best solutions below

0
On BEST ANSWER

I was able to figure this out with the help of Copilot. You can use a JavaScript function that checks if the row has any sub rows, and if it does then it adds a border:

library(reactable)

data <- MASS::Cars93[10:22, c("Manufacturer", "Model", "Type", "Price", "MPG.city")]

reactable(
  data,
  groupBy = "Manufacturer",
  defaultExpanded = TRUE,
  rowStyle = JS("function(rowInfo) {
    if (rowInfo.subRows.length) {
      return { borderBottom: '3px solid #800080' }
    }
  }"),
)