DT datatable selected row color: inconsistent behavior on IE and chrome

做~自己de王妃 提交于 2019-12-06 12:23:09

问题


I have an app, similar to below, which I'd like to customize the color of the selected row rendered via DT. My app code looks like below

library(shiny)
library(DT)

bkg_shade <-"#2c3e50" 

ui <- fluidPage(
  tags$style(HTML(paste0("table.dataTable tr.selected td, table.dataTable td.selected{background-color: ",
                        bkg_shade," !important;}"))),
  fluidRow(dataTableOutput("tbl"))
)
server <- function(input, output){
  output$tbl <- renderDataTable({
    datatable(mtcars)
  })

}

app <- shinyApp(ui = ui, server= server)
runApp(app)

It looks as expected on chrome, the selected row color is what I specified.

However, the selected row color is still the default color in IE.

Have anyone has experienced similar issue before? and how can I fix this so that the selected row color is also customized in IE?


回答1:


I had a very similar problem with my code and had nearly given up hope of finding a solution. However, a small tweak seems to fix it.

You'll notice the only real change is that tbody is inserted. You should be able to keep everything else as it is.

library(shiny)
library(DT)

bkg_shade <-"#2c3e50" 

ui <- fluidPage(
  tags$style(HTML(paste0("table.dataTable tbody tr.selected td, table.dataTable td.selected{background-color: ", bkg_shade," !important;}"))),
  fluidRow(dataTableOutput("tbl"))
)
server <- function(input, output){
  output$tbl <- renderDataTable({
    datatable(mtcars)
  })

}

app <- shinyApp(ui = ui, server= server)
runApp(app)


来源:https://stackoverflow.com/questions/46445537/dt-datatable-selected-row-color-inconsistent-behavior-on-ie-and-chrome

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