Skip to content

Commit

Permalink
coreOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Feb 1, 2024
1 parent ba1900b commit 9eb5851
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
8 changes: 6 additions & 2 deletions R/jstree.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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)){
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
43 changes: 43 additions & 0 deletions inst/essais/essai_expand-selected-onload-false.R
Original file line number Diff line number Diff line change
@@ -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)
)
2 changes: 2 additions & 0 deletions inst/htmlwidgets/jstreer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion man/jstree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9eb5851

Please sign in to comment.