r - How to remove the horizontal line between the header and the body in a DT::datatable

别来无恙 提交于 2021-01-28 12:23:55

问题


I want to remove the stripes in te limit between de table data and the header, or at least, change its color.

I want to make an schedule for teachers with their respective classroom.

                    options = (list(pageLength = 40, 
                                    dom = 't',
                                    ordering = FALSE,
                                    columnDefs = list(list(className = 'dt-center', targets = 0:5)),
                                    initComplete = JS("function(settings, json) {",
                                                      "$(this.api().table().header()).css({'background-color': '#3b5998', 'color': '#ffffff', 'border-right': '1px solid #ffffff'});","}"))
      )) %>% formatStyle(names(Profesor), 
                    border = '1px solid #ffffff',
                    fontSize = '15px',
                    color = '#f7f7f7', 
                    backgroundColor = styleEqual(c(NA, valores), c('#f7f7f7', rep('#8b9dc3',length(valores)))),
                    borderCollapse = TRUE
                    ) %>%
        formatStyle(columns = ' ',
                    backgroundColor = '#3b5998',
                    borderBottomColor = "#ffffff",
                    borderBottomStyle = "solid",
                    borderBottomWidth = "1px",
                    color = '#ffffff',
                    fontSize = "15px",
                    fontWeight = "bold",)
  })```


  [1]: https://i.stack.imgur.com/eMb9n.png

回答1:


With the headerCallback option:

headerCallback <- c(
  "function(thead, data, start, end, display){",
  "  $('th', thead).css('border-bottom', 'none');",
  "}"
)

datatable(iris, 
          options = 
            list(pageLength = 40, 
                 dom = 't',
                 ordering = FALSE,
                 headerCallback = JS(headerCallback),
                 columnDefs = list(list(className = 'dt-center', targets = 0:5)),
                 initComplete = JS("function(settings, json) {",
                                   "$(this.api().table().header()).css({'background-color': '#3b5998', 'color': '#ffffff', 'border-right': '1px solid #ffffff'});","}")))


来源:https://stackoverflow.com/questions/56533474/r-how-to-remove-the-horizontal-line-between-the-header-and-the-body-in-a-dtd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!