From 9eb58514452dded058c6f68853d88acfcba880f4 Mon Sep 17 00:00:00 2001 From: stla Date: Thu, 1 Feb 2024 20:00:30 +0100 Subject: [PATCH] coreOptions --- R/jstree.R | 8 +++- .../essai_expand-selected-onload-false.R | 43 +++++++++++++++++++ inst/htmlwidgets/jstreer.js | 2 + man/jstree.Rd | 5 ++- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 inst/essais/essai_expand-selected-onload-false.R diff --git a/R/jstree.R b/R/jstree.R index ca39611..89cec86 100644 --- a/R/jstree.R +++ b/R/jstree.R @@ -99,6 +99,7 @@ #' for the list of all available options #' @param theme jsTree theme, one of \code{"default"}, #' \code{"default-dark"}, or \code{"proton"} +#' @param coreOptions a named list of core options, for advanced usage #' #' @return A \code{htmlwidget} object. #' @@ -386,7 +387,8 @@ jstree <- function( contextMenu = FALSE, checkCallback = NULL, grid = NULL, - theme = "default" + theme = "default", + coreOptions = NULL ){ if(!isNodesList(nodes) && !isCallbackNodes(nodes) && !isAJAXnodes(nodes) && !isLAZYnodes(nodes)){ @@ -420,6 +422,7 @@ jstree <- function( ) stopifnot(is.null(grid) || isNamedList(grid)) stopifnot(isString(theme)) + stopifnot(is.null(coreOptions) || isNamedList(coreOptions)) # forward options using x x = list( data = nodes, @@ -438,7 +441,8 @@ jstree <- function( contextMenu = contextMenu, checkCallback = checkCallback %||% (dragAndDrop || contextMenu), grid = validateGrid(grid), - theme = match.arg(theme, c("default", "default-dark", "proton")) + theme = match.arg(theme, c("default", "default-dark", "proton")), + coreOptions = coreOptions ) # create widget diff --git a/inst/essais/essai_expand-selected-onload-false.R b/inst/essais/essai_expand-selected-onload-false.R new file mode 100644 index 0000000..497eb73 --- /dev/null +++ b/inst/essais/essai_expand-selected-onload-false.R @@ -0,0 +1,43 @@ +library(jsTreeR) + +nodes <- list( + list( + text = "RootA", + state = list(selected = TRUE, undetermined = FALSE), + type = "root", + children = list( + list( + text = "ChildA1", + state = list(selected = TRUE, undetermined = FALSE), + type = "child", + children = list(list(text = "ChildA12", + state = list(selected = TRUE, undetermined = FALSE), + type = "child")) + ), + list(text = "ChildA2", + state = list(selected = TRUE, undetermined = FALSE), + type = "child") + ) + ), + list( + text = "RootB", + state = list(selected = TRUE, undetermined = FALSE), + type = "root", + children = list( + list(text = "ChildB1", + state = list(selected = TRUE, undetermined = FALSE), + type = "child"), + list(text = "ChildB2", + state = list(selected = TRUE, undetermined = FALSE), + type = "child") + ) + ) +) + +types <- list(root = list(icon = FALSE), child = list(icon = FALSE)) + +jstree(nodes, + types = types, + checkboxes = TRUE, + coreOptions = list(expand_selected_onload = FALSE) +) diff --git a/inst/htmlwidgets/jstreer.js b/inst/htmlwidgets/jstreer.js index 3f2a152..be8a0a8 100644 --- a/inst/htmlwidgets/jstreer.js +++ b/inst/htmlwidgets/jstreer.js @@ -217,6 +217,8 @@ HTMLWidgets.widget({ } }; + $.extend(options.core, x.coreOptions); + if(x.types) options.types = x.types; if(x.dnd) options.dnd = x.dnd; diff --git a/man/jstree.Rd b/man/jstree.Rd index 3c2ac7d..cb2c51e 100644 --- a/man/jstree.Rd +++ b/man/jstree.Rd @@ -22,7 +22,8 @@ jstree( contextMenu = FALSE, checkCallback = NULL, grid = NULL, - theme = "default" + theme = "default", + coreOptions = NULL ) } \arguments{ @@ -141,6 +142,8 @@ for the list of all available options} \item{theme}{jsTree theme, one of \code{"default"}, \code{"default-dark"}, or \code{"proton"}} + +\item{coreOptions}{a named list of core options, for advanced usage} } \value{ A \code{htmlwidget} object.