question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

expand not working on first time

See original GitHub issue

Hi,

When adding a new node to tree it is not expanding when the parent node has been empty, but when there are children then it works. See the video: https://www.useloom.com/share/ce8709b4a27448e7a2eb0f56bbc92ad2

addLevel(parent) {
    let newLevel = {
      level_id: parent.data.id,
      name: parent.data.name + " copy",
    };

    this.levelService.addLevel(newLevel)
      .then(level => {
        parent.data.children = parent.data.children || [];
        parent.data.children.push(level.data);
        this.tree.treeModel.update();
        parent.expand();
      });
  }

<tree-root [nodes]="levels" [options]="treeOptions"
        (moveNode)="onMoveNode($event)"
        (activate)="onActivate($event)"
        (deactivate)="onDeactivate($event)"
        (event)="onEvent($event)"
      >
        <ng-template #treeNodeTemplate let-node="node" let-index="index">
          <div class="level">
            {{ node.data.name }}
            <button class="btn btn-sm btn-success float-right" (click)="addLevel(node)"><i class="fa fa-plus"></i></button>
          </div>

        </ng-template>
      </tree-root>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thieneditscommented, Feb 13, 2018

This is what worked for me

parentNode: TreeNode;
@ViewChild('tree') tree: TreeComponent;

ngAfterViewChecked() {
        //If parentNode exists
        if(this.parentNode) {
                //If node exists in treeModel
                if (this.tree.treeModel.getNodeById(this.parentNode.data.id)) {
                    this.tree.treeModel.getNodeById(this.parentNode.data.id).expand();
                }
        }
    }

addLevel(parent) {
   this.parentNode = parent;
}

It looks like you have to use one of the angular lifecycle after the view is rendered. Then inside there you can get the treeModel to get the node by id and call expand().

0reactions
tobiasengelhardtcommented, Jul 31, 2020

Closing this issue due to inactivity. Please open a new issue if the problem still exists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

expand not working on first time · Issue #513 - GitHub
Hi, When adding a new node to tree it is not expanding when the parent node has been empty, but when there are...
Read more >
Making a menu with collapse and expand... not working
Using flexbox to display the menu in a row when the screen is bigger. Once it hits the breakpoint, display the hamb icon....
Read more >
Excel Table Does Not Expand for New Data - Contextures Blog
If you notice that Excel tables don't automatically expand on your computer, to include new data, there might be a problem with the...
Read more >
Expand/collapse problem - JavaScript - SitePoint Forums
Some time ago, if I remember thanks to you, I made a new expand/collapse solution in js and css. The js is: $(".expandable").on("click" ......
Read more >
expand / collapse doesn't work on heading if it's set later
docx file, in the start I choose H1 I type my Heading, and then I press enter. Now there are two sides to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found