最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do you format the header of a table produced using the R DT (datatables) package - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论