daattali/timevis

Editable on item level not working

derekzoutendijk opened this issue · 2 comments

Hi,

I would like to disable editing of certain items, but it seems that the editable value is not taken over from my items. I have tried multiple editable options on the timevis level (e.g. editable = TRUE, FALSE, list(overwriteTime = TRUE, overrideItems = FALSE). All of them result in using the timevis option of editable, rather than my value for the single item. Am I missing something?

timevisDataGroups <- data.frame(id = c("Job1",
                                       "Job2"),
                                content = c("Job1",
                                            "Job2"),
                                subgroupStack = TRUE,
                                subgroupVisibility = TRUE,
                                style = "color: black;
                                            background-color: green;
                                            background-image: linear-gradient(top, red, red 70%, transparent 70%, transparent 100%);
                                            background-image: -webkit-linear-gradient(top, red, red 70%, transparent 70%, transparent 100%)")

timevisData <- data.frame(start = c("2022-04-26 09:00",
                                    "2022-04-26 09:00"),
                          end = c("2022-04-26 11:00",
                                  "2022-04-26 10:00"),
                          content = c("Employee1",
                                      "Employee2"),
                          group = c("Job1",
                                    "Job2"),
                          subGroup = c("Job1",
                                       "Job2"),
                          editable = c(TRUE,
                                       FALSE)) %>% 
  mutate(title = paste0(start, "-",end,": ", content, " working @",group))
timevis(data = timevisData, groups = timevisDataGroups, 
        options = 
          list(editable = TRUE, overridestackSubgroups = FALSE, stack = TRUE,
               multiselect = TRUE, multiselectperGroup = TRUE,
               showWeekScale = TRUE, verticalScroll = TRUE, maxHeight = "1000px"
          ))

Edit: I can get it working via the following callback, but that's not an ideal solution I suppose:

timevis(data = timevisData, groups = timevisDataGroups, 
        options = 
            list(editable = TRUE, overridestackSubgroups = FALSE, stack = TRUE,
                 multiselect = TRUE, multiselectperGroup = TRUE,
                 showWeekScale = TRUE, verticalScroll = TRUE, maxHeight = "1000px",
                 onMoving = htmlwidgets::JS("function(item, callback) {
                                                  if(item.group != 'Job2')
                                                  {
                                                    callback(item);
                                                  } 
                                               }")
            ))

Your sample code is unnecessarly long and complicated. I haven't tried reproducing your code for that reason, but I have verified that editable on single items does indeed work exactly as the documentation says. For example

timevis(data.frame(
    start = c("2022-04-28", "2022-04-29", "2022-04-30"),
    content = c("one","two","three"),
    editable = c(TRUE, FALSE, TRUE)
))

The first and third items are editable, the second isn't.

If you believe there is a bug you can open a new issue but please make it a minimal simple code sample

Looking at your code, it seems like you put the editable parameter in the groups dataframe instead of the data dataframe. The documentation only says that editable is for the data , not for groups.