【问题标题】:OnDoubleClick row reactableOnDoubleClick 行可反应
【发布时间】:2022-09-27 22:51:48
【问题描述】:

reactable 的文档提供了一种使用 custom action 定义的方法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\' })
    }
  }\")

reactable 是否连续提供OnDoubleClick 函数?

source code 显示了一个 utils.R 文件,其中包含一个 OnDoubleClick,但 R 中的可反应对象似乎没有公开这样的功能)。

    标签: javascript r reactable


    【解决方案1】:

    glin,reactable GitHub 存储库的所有者,回复:

    嗨,不支持双击的自定义操作,并且不会因为双击在网络上非常罕见,并且存在许多可访问性问题。它需要鼠标,并且不可能(或很难)使用键盘或触摸/移动设备触发。在 reactable 中添加自定义单击操作已经是一个错误,而没有提供从键盘执行此操作的方法,因此我更加犹豫是否要添加双击。

    但是,如果您使用 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)
            )
          }
        )
      )
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      相关资源
      最近更新 更多