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

Hard to find where to edit empty cells. #808

Open
jjesusfilho opened this issue May 8, 2020 · 5 comments
Open

Hard to find where to edit empty cells. #808

jjesusfilho opened this issue May 8, 2020 · 5 comments

Comments

@jjesusfilho
Copy link

If I have an editable table where one of the columns has a long text and the other is empty or NA, where I want the user to add a comment, he/she has a hard time finding where to click:

df  <-  tibble::tibble(comment = NA_character_, v2 ="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")

DT::datatable(df, editable=TRUE)

Is there a way to solve this issue?

@stla
Copy link
Collaborator

stla commented May 11, 2020

I don't understand what you mean: one can click anywhere in a cell. No?

@mtyszler
Copy link

Hi @jjesusfilho ,

This sounds to me much more like an usage problem than a package issue.

I suggest you simply initialize the cell with "Click here to edit" instead of NaN.

@jjesusfilho
Copy link
Author

jjesusfilho commented May 14, 2020

Hi @jjesusfilho ,

This sounds to me much more like an usage problem than a package issue.

I suggest you simply initialize the cell with "Click here to edit" instead of NaN.

Then the user has to delete that phrase. Ideally, a placeholder would work. Right now, I am using formatString to add a suffix indicating where to click. The advantage is that the suffix, though it keeps showing up, is ignored when the user saves the comments on the database.

@stla
Copy link
Collaborator

stla commented Jul 9, 2020

Here is how to set a placeholder:

library(shiny)
library(DT)

dat <- data.frame(
  Col1 = c("", ""),
  Col2 = c("a", "b")
)

CSS <- "
table td.withPlaceholder:empty:before {
  content: 'Edit me';
  color: gray;
}
"

ui <- fluidPage(
  tags$head(
    tags$style(HTML(CSS))
  ),
  br(),
  DTOutput("dtable")
)

server <- function(input, output){
  
  output[["dtable"]] <- renderDT({
    datatable(
      dat, 
      rownames = FALSE,
      editable = "cell",
      options = list(
        columnDefs = list(
          list(targets = 0, className = "withPlaceholder")
        )
      )
    )
  })
  
}

shinyApp(ui, server)

@jjesusfilho
Copy link
Author

Here is how to set a placeholder:

library(shiny)
library(DT)

dat <- data.frame(
  Col1 = c("", ""),
  Col2 = c("a", "b")
)

CSS <- "
table td.withPlaceholder:empty:before {
  content: 'Edit me';
  color: gray;
}
"

ui <- fluidPage(
  tags$head(
    tags$style(HTML(CSS))
  ),
  br(),
  DTOutput("dtable")
)

server <- function(input, output){
  
  output[["dtable"]] <- renderDT({
    datatable(
      dat, 
      rownames = FALSE,
      editable = "cell",
      options = list(
        columnDefs = list(
          list(targets = 0, className = "withPlaceholder")
        )
      )
    )
  })
  
}

shinyApp(ui, server)

This is great.

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

3 participants