Remove header row in datatable
Asked Answered
V

3

9

I'm trying to remove the header row in a DT datatable, does anyone know if there's an option for doing this?

Minimal example:

#SERVER.R
output$myTable <- renderDataTable({
  datatable(dataset, rownames = FALSE, selection = 'none', options = list(dom = 't'))
})

#UI.R
dataTableOutput('myTable')
Violet answered 28/10, 2015 at 16:24 Comment(1)
Related: #48296399Sadoff
O
11

Just add colnames = NULL to your datatable()

datatable(mtcars, rownames = FALSE,colnames=NULL, selection = 'none', options = list(dom = 't'))

See ?datatable

Obvert answered 28/10, 2015 at 16:46 Comment(0)
S
3

Sebastian's answer from Oct 28 '15 did not work for me inside renderDataTable(datatable(...)). Using colnames = NULL inside datatable(...) removed all data from the table. I had to use colnames = "" to remove the table headers.

Samaritan answered 12/3, 2020 at 6:30 Comment(0)
L
3

Adding colnames = NULL no longer works and it renders an empty table. You can use headerCallBack option to add a css that hides the header row to achieve this.

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

datatable(mtcars, 
          rownames = FALSE,
          colnames=NULL, 
          selection = 'none', 
          options = list(
            dom = 't',
            headerCallback = JS(headerCallback)
          )
)

Loincloth answered 25/8, 2020 at 10:30 Comment(1)
Just tried with colnames = NULL and the column names were gone (Nov 22).Bac

© 2022 - 2024 — McMap. All rights reserved.