rowreorder glitch

Open
#1,146 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, r
Domain
frontend, web-dev

Research direction

Start by running the linked Shiny example with DT 0.33 and reproduce the double-click in the first column while inspecting the RowReorder interaction and console error. Use the RowReorder configuration and callback shown in the issue as the entry points. Done means double-clicking no longer inserts a duplicate or leaves a row attached to the cursor, while normal drag-and-drop reordering still works.

Written by the indexing model from the issue text.

Description

Hello,

I'm attempting to get the "RowReorder" extension to work and I'm noticing that if I double click on any cell in the first column (the column used for drag and drop) a glitch occurs where a duplicated row is inserted into the table, the double clicked row is attached to the cursor but cannot be dropped and additionally the following error is displayed in the console:

Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at P.isPlainObject.d (<anonymous>:4:12252)
    at i._mouseUp (<anonymous>:4:5508)
    at HTMLDocument.<anonymous> (<anonymous>:4:4073)
    at HTMLDocument.dispatch (jquery.js:5430:27)
    at v.handle (jquery.js:5234:28)

To reproduce you can use this example from r-bloggers

library(shiny)
library(DT)

dat <- data.frame(
  Type  = c("A", "B", "C", "D"),
  Value = c(100, 90, 80, 70)
)

js <- c(
  "table.on('row-reorder', function(e, details, edit) {",
  sprintf("  var order = [%s];", toString(0:(nrow(dat)-1))),
  "  for(entry of details) {",
  "    order[entry.newPosition] = entry.oldPosition;",
  "  }",
  "  Shiny.setInputValue('newOrder', order);",
  "});"
)

showRowNames <- TRUE

ui <- fluidPage(
  br(),
  DTOutput("table")
)

server <- function(input, output, session){
  
  output$table <- renderDT({
    datatable(
      dat,
      rownames = showRowNames,
      extensions = "RowReorder",
      callback = JS(js),
      options = list(rowReorder = TRUE)
    )
  }, server = TRUE)
  
  proxy <- dataTableProxy("table")
  
  Dat <- reactiveVal(dat)
  
  observeEvent(input$newOrder, {
    dat0 <- Dat()
    dat1 <- dat0[input$newOrder + 1, ]
    replaceData(proxy, dat1, resetPaging = FALSE, rownames = showRowNames)
    Dat(dat1)
  })
  
}

shinyApp(ui, server)

Versions of shiny and DT: shiny_1.8.1.1 and DT_0.33

Here's screen capture of the issue
issue

My temporary solution is to set cancelable = TRUE option for rowReorder and add a JS callback to set a shinyInputValue cancel_row_reorder so that if input$cancel_row_reorder is triggered by pressing Esc then the datatable is rendered to its previous state.


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Dominant language
JavaScript
Stars
621
Forks
177
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/DT

All issues in rstudio/DT

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.