admin管理员组

文章数量:1415684

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.

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.

Share Improve this question edited Aug 30, 2021 at 0:53 M-- 29.6k10 gold badges70 silver badges106 bronze badges asked Nov 25, 2015 at 0:15 Chris FacerChris Facer 811 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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.

本文标签: