8
votes

The R package DT uses the datatables JavaScript library to draw nice-looking tables. I can determine the formatting of the cells in the table using the formatStyle() function, but there does not seem to be a function to format the column headers. Is there a way to format the headers of the table, for example fonts, alignments etc?

Many questions about DT on Stack Overflow are specific to R Shiny, and I am not using R Shiny.

1

1 Answers

5
votes

You may use the "initComplete" function in "options" to callback a javascript code directly. Try the following R code to format the column headers to a 12 pixels font size:

datatable(
    iris,
    options = list(
        initComplete = JS("function(settings, json) {$(this.api().table().header()).css({'font-size' : '12px'});}")
        )
)

There are many other examples at http://rstudio.github.io/DT/

Regards.