Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rowreorder glitch #1146

Open
3 tasks done
beemnet-Regn opened this issue Jul 31, 2024 · 0 comments
Open
3 tasks done

rowreorder glitch #1146

beemnet-Regn opened this issue Jul 31, 2024 · 0 comments

Comments

@beemnet-Regn
Copy link

beemnet-Regn commented Jul 31, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant