How to set isExpanded status of added node to true
See original GitHub issueHey there,
I created a function that adds a node, updates the tree, does everything correctly, except by default it seems to want to not be expanded. If I try to add other nodes inside of that node, the nodes do not show up because the node is not expanded. I thought if I set isExpanded: true, then the node would automatically be expanded. I’m using angular2-tree-component 2.6.1
.
Here is my function:
addSection() {
this.items.push({
id: 0,
isExpanded: true,
isSection: true,
expanded: false,
name: '[Section name needed]',
children: []
});
// Update the tree model to reflect changes
this.tree.treeModel.update();
}
Do you have any thoughts?
Thanks in advance!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:17 (3 by maintainers)
Top Results From Across the Web
How to set isExpanded status of added node to true #141
I'm using angular2-tree-component 2.6.1 . Here is my function: addSection() { this.items.push({ id: 0, isExpanded: true, isSection ...
Read more >c# - Setting IsExpanded on a WPF TreeViewItem from ...
There are a few things wrong here. The first is that you are setting the property TreeViewItem.IsSelected on a HierarchicalDataTemplate .
Read more >How to programmatically expand a tree view control? - MSDN
I want to programmatically expand all the nodes on a tree view control. ... I suggest when you set 'IsExpanded = true' then...
Read more >Need to programmatically expand tree node if a child ...
I tried adding an IsExpanded property to my model class and ... and then setting IsExpanded=true for the parent node meeting my criteria....
Read more >bind property to IsExpanded of XamGridTree in TwoWay
Another 50 percent is how to make XamTreeGrid actually expand node when IsOpen is set to true upon binding? To reproduce, assign value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey guys, I’m glad you solved this on your own. I was on a long sickness leave and couldn’t help.
The solution is what was proposed by @romanovma .
Basically isExpanded field is a tricky one. I only look at that field the first time the tree is rendered, or whenever async children are loaded. The state of expanded nodes is saved inside the treeModel, and not on the nodes themselves. I’m trying to avoid 2-way binding to properties of the nodes. It is not good practice to change the data that was given to the tree.
@snstarosciak you should update the tree model before you use its methods which means that first run:
and then
hope that helps