悬停 header 而不是 fixedHeader
Hover header instead of fixedHeader
我正在处理这个 issue。
我已经尝试了一些 css 解决方案,但我没有设法解决它。
我最终决定悬停每个单元格以显示行名(第一列)和列名(header)。
以下代码可以解决问题 、
shinyApp(
ui = fluidPage(
DT::dataTableOutput("mtcarsTable")
),
server = function(input, output) {
output$mtcarsTable <- DT::renderDataTable({
DT::datatable(datasets::mtcars[,1:3],
extensions = c('FixedColumns'), selection=list(mode="single", target="cell"), class = 'cell-border stripe', escape = F ,
options = list(rowCallback = JS(
"function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
"var full_text = aData[0] + ','+ aData[1];",
"var headers = Array.prototype.slice.apply(document.querySelectorAll('th'));",
"$('td', nRow).each(function(i) {
this.title = [aData[0], headers[i].innerText].filter(Boolean).join(', ');
});",
"}")
)
)
})
}
)
不幸的是,这似乎与 formatStyle 不兼容:
shinyApp(
ui = fluidPage(
DT::dataTableOutput("mtcarsTable")
),
server = function(input, output) {
output$mtcarsTable <- DT::renderDataTable({
DT::datatable(datasets::mtcars[,1:3],
extensions = c('FixedColumns'), selection=list(mode="single", target="cell"), class = 'cell-border stripe', escape = F ,
options = list(rowCallback = JS(
"function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
"var full_text = aData[0] + ','+ aData[1];",
"var headers = Array.prototype.slice.apply(document.querySelectorAll('th'));",
"$('td', nRow).each(function(i) {
this.title = [aData[0], headers[i].innerText].filter(Boolean).join(', ');
});",
"}")
)
) %>%
formatStyle(columns = 1, backgroundColor = styleInterval(c(19,20,22), c('red','green','yellow', 'black')))
})
}
)
当我执行那个额外的步骤时,既没有错误也没有呈现数据表。
我正在寻找:能够混合使用 rowCalllback 和 Styleinterval,或者通常来说,更好的解决方案让用户知道他在大型数据表中的确切位置。
提前致谢。
我会这样处理工具提示:
library(DT)
datatable(head(iris),
options=list(initComplete = JS(c(
"function(settings){",
" var table = settings.oInstance.api();",
" var ncols = table.columns().count();",
" var nrows = table.rows().count();",
" for(var i=0; i<nrows; i++){",
" var rowname = table.cell(i,0).data();",
" for(var j=1; j<ncols; j++){",
" var headerName = table.column(j).header().innerText;",
" var cell = table.cell(i,j);",
" cell.node().setAttribute('title', rowname + ', ' + headerName);",
" }",
" }",
"}")))
)
我正在处理这个 issue。 我已经尝试了一些 css 解决方案,但我没有设法解决它。
我最终决定悬停每个单元格以显示行名(第一列)和列名(header)。
以下代码可以解决问题
shinyApp(
ui = fluidPage(
DT::dataTableOutput("mtcarsTable")
),
server = function(input, output) {
output$mtcarsTable <- DT::renderDataTable({
DT::datatable(datasets::mtcars[,1:3],
extensions = c('FixedColumns'), selection=list(mode="single", target="cell"), class = 'cell-border stripe', escape = F ,
options = list(rowCallback = JS(
"function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
"var full_text = aData[0] + ','+ aData[1];",
"var headers = Array.prototype.slice.apply(document.querySelectorAll('th'));",
"$('td', nRow).each(function(i) {
this.title = [aData[0], headers[i].innerText].filter(Boolean).join(', ');
});",
"}")
)
)
})
}
)
不幸的是,这似乎与 formatStyle 不兼容:
shinyApp(
ui = fluidPage(
DT::dataTableOutput("mtcarsTable")
),
server = function(input, output) {
output$mtcarsTable <- DT::renderDataTable({
DT::datatable(datasets::mtcars[,1:3],
extensions = c('FixedColumns'), selection=list(mode="single", target="cell"), class = 'cell-border stripe', escape = F ,
options = list(rowCallback = JS(
"function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
"var full_text = aData[0] + ','+ aData[1];",
"var headers = Array.prototype.slice.apply(document.querySelectorAll('th'));",
"$('td', nRow).each(function(i) {
this.title = [aData[0], headers[i].innerText].filter(Boolean).join(', ');
});",
"}")
)
) %>%
formatStyle(columns = 1, backgroundColor = styleInterval(c(19,20,22), c('red','green','yellow', 'black')))
})
}
)
当我执行那个额外的步骤时,既没有错误也没有呈现数据表。
我正在寻找:能够混合使用 rowCalllback 和 Styleinterval,或者通常来说,更好的解决方案让用户知道他在大型数据表中的确切位置。
提前致谢。
我会这样处理工具提示:
library(DT)
datatable(head(iris),
options=list(initComplete = JS(c(
"function(settings){",
" var table = settings.oInstance.api();",
" var ncols = table.columns().count();",
" var nrows = table.rows().count();",
" for(var i=0; i<nrows; i++){",
" var rowname = table.cell(i,0).data();",
" for(var j=1; j<ncols; j++){",
" var headerName = table.column(j).header().innerText;",
" var cell = table.cell(i,j);",
" cell.node().setAttribute('title', rowname + ', ' + headerName);",
" }",
" }",
"}")))
)