可达表的文档提供了一种使用自定义动作定义onClick的方法。
onClick = JS("function(rowInfo, column) {
// Only handle click events on the 'details' column
if (column.id !== 'details') {
return
}
// Display an alert dialog with details for the row
window.alert('Details for row ' + rowInfo.index + ':\\n' + JSON.stringify(rowInfo.values, null, 2))
// Send the click event to Shiny, which will be available in input$show_details
// Note that the row index starts at 0 in JavaScript, so we add 1
if (window.Shiny) {
Shiny.setInputValue('show_details', { index: rowInfo.index + 1 }, { priority: 'event' })
}
}")可达表是否在行上提供OnDoubleClick函数?
( 源代码显示一个utils.R文件,其中包含一个OnDoubleClick,但R中的可达对象似乎没有公开这样的函数)。
发布于 2022-09-27 14:51:48
可达的格林存储库的所有者GitHub响应道:
嗨,不支持双击的自定义操作,也不会支持,因为双击在web上非常少见,有许多可访问性问题。它需要一个鼠标,不可能(或很难)触发使用键盘或触摸/移动设备。在“可达表”中添加自定义单击操作已经是一个错误,而没有提供一种从键盘上实现此操作的方法,因此我更不愿意添加双击。
但是,如果使用dblclick事件处理程序呈现表中的自定义元素,则可以将双击添加到表中。例如,下面是一列自定义呈现的按钮,在dblclick事件上运行JS代码:
library(reactable)
data <- cbind(
MASS::Cars93[1:5, c("Manufacturer", "Model", "Type", "Price")],
details = NA
)
reactable(
data,
columns = list(
details = colDef(
name = "",
sortable = FALSE,
cell = function(value, index, name) {
htmltools::tags$button(
"Show details",
ondblclick = sprintf("window.alert('double clicked cell %s in column %s')", index, name)
)
}
)
)
)https://stackoverflow.com/questions/73554175
复制相似问题