在reactable中格式化groupby行

piok6c0g  于 12个月前  发布在  React
关注(0)|答案(1)|浏览(167)

reactable中,是否有方法对groupBy标题的整行进行样式设置?例如,在底部添加一个边框,如下所示:


的数据
表格代码:

library(reactable)

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

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

字符串

mefy6pfw

mefy6pfw1#

我在Copilot的帮助下解决了这个问题。你可以使用一个JavaScript函数来检查该行是否有任何子行,如果有,它就会添加一个边框:

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' }
    }
  }"),
)

字符串

相关问题