DT :: datatable定制条纹

时间:2017-03-10 01:22:31

标签: css r dt

R中的DT包提供了一组惊人的功能,可以在您的Rmarkdown文档或Shiny Apps中创建交互式表格。插图/帮助页面提供了非常丰富的信息,可以解决大多数问题。见here

然而,当谈到改变条纹的颜色时,我很难找到一个简单的解决方案。

根据答案here,我提供以下内容以更改条纹的颜色:

markets_list <- c("GC=F","SI=F","PL=F","CL=F","BZ=F","^TNX","^TYX","^VIX")
Now_Quotes <- getQuote(markets_list) %>% 
dplyr::mutate(names = c("Gold","Silver","Platinum","Oil","Brent","Treas10Y","Treas30Y","VIX"))

datatable(Now_Quotes[,c(9,2)],
rownames = FALSE,
colnames = "",
options = list(dom = 't',bSort=FALSE,
columnDefs = list(list(className = 'dt-center', targets = c(0,1))),
rowCallback=JS('function(row,data) {if($(row)["0"]["_DT_RowIndex"] % 2 == 1) $(row).css("background","#737373")}'),
initComplete = JS("function(settings, json) {$(this.api().table().header()).css({'background-color': '#252525', 'color':     '#fff'});}")))

显然,这似乎不是正确的方法,因为应该可以根据简单的css规则更改颜色。有人可以提供正确的方法。感谢

0 个答案:

没有答案