Skip to content

Commit

Permalink
search update
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed May 7, 2020
1 parent 1b89668 commit 3e3a75e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinytreeview
Title: Tree View for 'shiny' Applications
Version: 0.0.0.9000
Version: 0.0.1.9000
Authors@R:
c(person(given = "Victor",
family = "Perrier",
Expand Down
2 changes: 1 addition & 1 deletion R/server-treeview.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ searchTreeview <- function(inputId,
collapse_before = TRUE,
session = shiny::getDefaultReactiveDomain()) {
message <- list(search = list(
pattern = pattern,
pattern = list1(pattern),
collapse = collapse_before,
options = list(
ignoreCase = ignore_case,
Expand Down
20 changes: 16 additions & 4 deletions inst/assets/bootstrap-treeview/treeview-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,31 @@ $.extend(treeviewInputBinding, {
if (data.search.collapse) {
tree.collapseAll();
}
tree.search(data.search.pattern, data.search.options);
if (data.search.pattern.length > 1) {
data.search.pattern.map(function(pattern) {
tree.search(pattern, data.search.options);
});
} else {
tree.search(data.search.pattern, data.search.options);
}
}
if (data.hasOwnProperty("expand")) {
if (data.expand.hasOwnProperty("nodeId")) {
var expandedNode = tree.findNodes("^" + data.expand.nodeId + "$", "nodeId");
var expandedNode = tree.findNodes(
"^" + data.expand.nodeId + "$",
"nodeId"
);
tree.expandNode(expandedNode, data.expand.options);
} else {
tree.expandAll(data.expand.options);
}
}
if (data.hasOwnProperty("collapse")) {
if (data.collapse.hasOwnProperty("nodeId")) {
var collapsedNode = tree.findNodes("^" + data.collapse.nodeId + "$", "nodeId");
var collapsedNode = tree.findNodes(
"^" + data.collapse.nodeId + "$",
"nodeId"
);
tree.collapseNode(collapsedNode);
} else {
tree.collapseAll();
Expand Down Expand Up @@ -88,7 +100,7 @@ $.extend(treeviewInputBinding, {
});
}
var nodes = tree.getNodes().map(function(o) {
return {text: o.text, nodeId: o.nodeId, parentId: o.parentId};
return { text: o.text, nodeId: o.nodeId, parentId: o.parentId };
});
Shiny.onInputChange(el.id + "_nodes:treeview.nodes", nodes);
});
Expand Down

0 comments on commit 3e3a75e

Please sign in to comment.