rowreorder glitch
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
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
- [x] I have fully read the issue guide at https://yihui.org/issue/.
- [x] 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.
- [x] 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.