How to format the header of a table created using the R DT package (datatables)

The R DT package uses a datatables JavaScript data library to draw pretty tables. I can determine the formatting of the cells in the table using the formatStyle () function, but there seems to be no function to format the column headers. Is there a way to format table headers like fonts, alignments, etc.?

Many DT stack overflow questions are specific to R Shiny, and I don't use R Shiny.

+4
source share
1 answer

You can use the "initComplete" function in "options" to directly call javascript code. Try using the following R code to format column headings to a font size of 12 pixels:

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.imtqy.com/DT/

Sincerely.

0
source

Source: https://habr.com/ru/post/1617349/


All Articles