DT::datatable customization stripes

柔情痞子 提交于 2020-01-24 12:13:11

问题


The DT package within R provides an amazing set of functions to create interactive tables within your Rmarkdown documents or Shiny Apps. The vignette / help page is very informative and will help with most problems. See here

However, when it comes down to changing the color of the stripes, I'm struggling to find a straightforward solution.

Based on the answer here, I came with the following to change the color of the stripes:

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'});}")))

Clearly this does not seem to be the right way, as it should be possible to change the colors based on simple css rules. Can someone please provide the right way. Thanks

来源:https://stackoverflow.com/questions/42708508/dtdatatable-customization-stripes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!