问题
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