r - 如何禁用 R Datatable 中特定列的双击反应性
问题描述
我正在我的 Shiny 应用程序中处理 DT,其中包含 Shiny Input 对象和一些可编辑的列。
这是一个可重现的例子,
library(shiny)
library(DT)
ui <- fluidPage(
fluidRow(
DTOutput('table1')
)
)
helper_fun <- function(FUN, len, id, ...) {
inputs = character(len)
for (i in seq_len(len)) {
inputs[i] = as.character(FUN(paste0(id, i), selected = 1, ...))
}
inputs
}
server <- function(input, output, session) {
output$table1 <- renderDT({
dat <- data.frame(Name = c('A', 'B')
, column1 = helper_fun(FUN = selectInput, len = length(2), id = 'selector_', label = NULL, choices = c(1, 2), width="100px")
)
dat
}, editable = list(target = 'cell', disable = list(columns = c(2))), server = FALSE, escape = FALSE
, options = list(preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')))
}
shinyApp(ui, server)
我希望能够编辑 1 列并禁用对具有闪亮输入值的列的编辑。使用editable = list(target = 'cell', disable = list(column = c(2)))
不会产生预期的效果,因为这会禁用编辑,但在html
双击单元格时会暴露底层。
如何在某些列上禁用此双击效果?
解决方案
这是一种方法:
CSS <- "
table tbody td:nth-child(3) {pointer-events: none;}
table tbody td:nth-child(3)>div {pointer-events: auto;}
"
ui <- fluidPage(
tags$head(tags$style(HTML(CSS))),
fluidRow(
DTOutput('table1')
)
)
推荐阅读
- javascript - 如何在 React 中动态读取通过 Netlify CMS 创建的 Markdown 文件的特定部分?
- azure - 如何处理与 Azure 存储等服务的连接
- c# - 水晶报表自动舍入小数
- text - 在输出中的每个字符串后添加一些空格
- react-native - 删除 eslint error '解析错误:意外的令牌,预期的;(致命)'在反应本机代码中
- mysql - MySQL 中带连接的慢查询
- jquery - 从 Ajax 的请求头中删除 Cookie,除了一些
- android - RecyclerView 在活动开始之前滚动到顶部
- python - 将格式为 68.830320 的字符串列表转换为“时间”格式,不带日期信息。时间格式为秒.毫秒
- dart - Flutter-无法从 StreamBuilder 加载 Widget