lumiukko
lumiukko

Reputation: 259

R DT:datatable remove .no-footer border-bottom

Trying to remove the footer border from a DT:datatable in R.

Looking at this datatable, I found the following code to eliminate the border (indicated in red) between the column names (which are empty "") and the data:

  headerCallback <- c(
    "function(thead, data, start, end, display){",
    "  $('th', thead).css('border-bottom', 'none');",
    "}"
  ),
DT::datatable(
      data = myData(),
      class = "compact",
      rownames = FALSE,
      colnames = c("",""),
      caption = tags$caption(myTitle, style = "color:black"),
      options = list(
        dom = 't',
        ordering = FALSE,
        paging = FALSE,
        searching = FALSE,
        headerCallback = JS(headerCallback)
      )
    )

  })

What I'm trying to do is now eliminate the bottom black line in the image. I found the following links that seem to be what I'm looking for, but now sure how to incorporate them into what I have:

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

How To Remove Black Lines

When I inspect the element on the webpage, and expand <table> I can un-check this box which removes the bottom black line and gives me what I want. However, not sure how to write that into my existing or a new callback function.

Upvotes: 2

Views: 2932

Answers (1)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84529

You can do:

datatable(
  data = iris[1:5,1:2],
  class = "compact",
  rownames = FALSE,
  colnames = c("",""),
  callback = JS("$('table.dataTable.no-footer').css('border-bottom', 'none');"),
  options = list(
    dom = 't',
    ordering = FALSE,
    paging = FALSE,
    searching = FALSE,
    headerCallback = JS(headerCallback)
  )
)

Upvotes: 4

Related Questions