- Home
- Forum
- ASP.NET MVC
- Expand node and childs
Expand node and childs
How can I expand/collapse the node AND his childs by javascript?
This only collpase the root of the treeview. But if the user open it again, the nodes inside root, has been no modified. They still open/close. Also I don'w tant to collpase/expand all the treeview. Only a specific node.
It collapse the node. However its child are not modified. Same problem before.
Here i'm trying to collpase the node, check if it has childs, and collapse them. However when treeviewObj.collapseNode(child); is executed, the function ends, and the next code is never executed.
As you can see, "Son" and "Daugher" are collapse, due the user had collpased Father node.
This is what i tried so far:
1º try
| var treeviewObj = $("#treeInstalaciones").data("ejTreeView"); treeviewObj.collapseAll(); |
2º try:
| var treeviewObj = $("#treeInstalaciones").data("ejTreeView"); treeviewObj.collapseNode(treeviewObj.getSelectedNode()[0]); |
3º try:
function collapseNodeAndChild(itemNode) { debugger; var treeviewObj = $("#treeInstalaciones").data("ejTreeView"); var nodesToCollapse = []; nodesToCollapse.push(itemNode); while (nodesToCollapse.length > 0) { var child = nodesToCollapse[0]; nodesToCollapse.pop(child); treeviewObj.collapseNode(child); //When this instrucction its executed, it exit the function, and the next code its not executed. for (i = 0; i < child.childNodes.length; i++) { var childInner = child.childNodes[i]; if (childInner.innerHTML.startsWith("<ul ")) { for (j = 0; j < childInner.childNodes.length; j++) { if (childInner.innerHTML.startsWith("<li ")) nodesToCollapse.push(childInner[j]); } } } } } |
When i need is:
INITIAL STATE
- GrandFahter
- Father
- Son
- Car
- Bike
- Daugther
- Bike
THE USER COLLAPSE THE NODE "FATHER" CLICKING A BUTTON WHICH EXECUTE SOME JAVASCRIPT CODE
- GrandFahter
- Father
THE USER OPEN THE NODE FATHER CLICKIN ON THE TREEVIEW
- GrandFahter
- Father
- Son
- Daugther
SIGN IN To post a reply.
2 Replies
JA
Jaime
April 12, 2016 12:37 PM UTC
4º Try (After Update to version 14.1451.0.41)
function collapseNodeAndChild(itemNode) { debugger; var treeviewObj = $("#treeInstalaciones").data("ejTreeView"); var nodesToCollapse = []; nodesToCollapse.push(itemNode); for (i = 0; i < nodesToCollapse.length; i++) { var child = nodesToCollapse[i]; for (j = 0; j < child.childNodes.length; j++) { var childInner = child.childNodes[j]; if (childInner.innerHTML.indexOf("<ul ") >= 0) { for (k = 0; k < childInner.childNodes.length; k++) { var childLI = childInner.childNodes[k]; nodesToCollapse.push(childLI); } } } } var nodesReverse = nodesToCollapse.reverse(); while (nodesReverse.length > 0) { var child = nodesReverse[0]; nodesReverse.splice(0, 1); treeviewObj.collapseNode(child); } } |
Whith this code only the last child is collapsed. BUT, if execute in the chrome console nodesReverse.splice(0, 1); before entering the while, the second child is collapsed!!
It seems like a bug. I have checked that, If execute in the console the instruction nodesReverse.splice(0, 1); X times before entering the while, I can collapse every child with no problem. However it seems that it only allow to collapse 1 node.
PR
Piramanayagam Ramakrishnan
Syncfusion Team
April 13, 2016 12:54 PM UTC
Hi Jaime,
We have checked with your query and created a new incident under your account to track the status of the issue reported in this forum. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
Regards,
Piramanayagam R
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
JA Jaime
- Apr 12, 2016 10:31 AM UTC
- Apr 13, 2016 12:54 PM UTC