数据表中的固定列标题忽略背景颜色

问题描述 投票:0回答:1

我有一个表格,显示四个不同渠道 12 个月内两个不同单位的数据。我需要当我向右滚动时,包含频道信息的第一列保持在原位,以便我可以看到我正在查看的信息。但是,在我固定第一列后,它完全忽略背景颜色参数,但不忽略颜色,这使其完全白色。我需要它与标题的其余部分具有相同的颜色。

这就是它的样子:

enter image description here

这就是我需要的样子:

enter image description here

这是我的代码:

fix_doubled_months <- function(month){
  
  month_1 <- str_extract(month, "[0-9]{6}")
  
  month_final <- character(length(month))
  
  month_final[str_detect(month, "dollar")] <- month_1[str_detect(month, "dollar")]
  month_final[str_detect(month, "lbs")] <- paste0(" ", month_1[str_detect(month, "lbs")], " ")
  
  return(month_final)
  
}

distribution_summary <- tibble(
  date = rep(seq(from = as.Date("2023-01-01"), length.out = 12, by = "+1 month"), times = 8),
  channels = rep(rep(paste0("Channel ", 1:4), each = 12), 2),
  value = round(rnorm(96, 500, 100), 2),
  unit = rep(c("lbs", "dollars"), each = 48)
) |> 
  mutate(date = format(date, format = "%Y%m"),
         date_unit = paste0(date, "_", unit)) |> 
  select(-c(date, unit)) |> 
  pivot_wider(names_from = date_unit, values_from = value) |> 
  rename_at(vars(matches("^[0-9]{6}_")), fix_doubled_months)

container_summary <- withTags(table(
  class = "display",
  thead(
    tr(
      th(rowspan = 1, ""),
      th(colspan = (length(distribution_summary) - 2)/2, "Lbs"),
      th(colspan = (length(distribution_summary) - 2)/2, "$"),
    ),
    tr(
      lapply(names(distribution_summary), th)
    )
  )
))

distribution_summary |> 
  datatable(
    rownames = FALSE,
    extensions = "FixedColumns",
    container = container_summary,
    options = list(fixedColumns = list(leftColumns = 1),
                   scrollX = TRUE,
                   scrollY = FALSE,
                   dom = "t",
                   initComplete = JS(
                     "function(settings, json) {",
                     "$(this.api().table().header()).css({'background-color': '#4F2170', 'color': '#FFFFFF', 'white-space': 'nowrap'});",
                     "}"
                   ))) |>
  formatStyle(names(distribution_summary), "white-space" = "nowrap") |>
  formatStyle("channels", backgroundColor = "#4F2170", color = "#FFFFFF", fontWeight = "bold")
javascript css r dt
1个回答
0
投票

嗨,所以我很聪明,我可以回答这个非常好的问题,所以当你的背景颜色有争论时,他们会打电话给离婚律师,他们必须去婚姻调解或离婚,如果他们这样做,那么你应该选择你想和妈妈还是爸爸一起去,但这很难选择,因为是的

© www.soinside.com 2019 - 2024. All rights reserved.