Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the tree node #1399

Closed
wenqi73 opened this issue May 7, 2018 · 4 comments
Closed

Remove the tree node #1399

wenqi73 opened this issue May 7, 2018 · 4 comments

Comments

@wenqi73
Copy link
Member

wenqi73 commented May 7, 2018

What problem does this feature solve?

Remove the tree node

What does the proposed API look like?

import { Component, OnInit, ViewChild } from '@angular/core';
import { NzFormatEmitEvent, NzTreeComponent, NzTreeNode } from 'ng-zorro-antd';

@Component({
  selector: 'nz-demo-tree-method',
  template: `
    <nz-tree
      #nzTree
      [(ngModel)]="nodes"
      (nzClick)="remove($event)"
    >
    </nz-tree>`
})

export class NzDemoTreeMethodComponent implements OnInit {
  @ViewChild('nzTree') nzTree: NzTreeComponent;
  nodes = [
    new NzTreeNode({
      title   : 'root1',
      key     : '1001',
      children: [
        {
          title   : 'child1',
          key     : '10001',
          children: [
            {
              title   : 'child1.1',
              key     : '100011'
            }
          ]
        }
      ]
    })
  ];

  remove(e: any): void {
    e.node.remove();
  }

  ngOnInit(): void {
  }
}
@zhuguohua19820515
Copy link

this function is very important, I think the clearChildren need to add index or key ,like this: node.clearChildren (index: int) or node.clearChildren (key: string)

@wenqi73
Copy link
Member Author

wenqi73 commented May 30, 2018

It can be used like this:

export class NzDemoTreeMethodComponent {
  nodes = [
    // ...
  ];

  remove(node: NzTreeNode): void {
    const nodes: NzTreeNode[] = node.parentNode ? node.parentNode.children : this.nodes;
    nodes.splice(nodes.findIndex(n => n.key === node.key), 1);
  }
}

I try to add the function into NzTreeNode, but I can not get the rootNodes

@IonelLupu
Copy link

IonelLupu commented Mar 31, 2020

I see the docs don't show anything about using ngModel and @wenqi73 's solution is based on that. The question is, how do you delete a node if it is in the root? Using node.remove() works only for child nodes but not for nodes that are at the root of the tree.

Updating the nodes manually will produce a undesirable flicker animation as seen in this example. Using nzNoAnimation is not a solution since we don't have those beautiful animations anymore. :(

Ricbet pushed a commit to Ricbet/ng-zorro-antd that referenced this issue Apr 9, 2020
…Node (NG-ZORRO#2976)

refactor(module: tree): fix bugs and add extra functions

refactor(module: tree): fix spec

refactor(module: tree): add doc

refactor(module: tree): fix doc

refactor(module: tree): support getTreeNodeByKey

close NG-ZORRO#1998 close NG-ZORRO#2370 close NG-ZORRO#2655 close NG-ZORRO#2724 close NG-ZORRO#2273 close NG-ZORRO#1399 close NG-ZORRO#2208 close NG-ZORRO#2384 NG-ZORRO#2375
@AffanAzeem7
Copy link

AffanAzeem7 commented Jun 17, 2020

can we remove children word from our nznode data and used another word for that having array like that
nodes = [
{

  title: 'xyz',
  key: '0-0',
  Resellers: [
    {
      title: 'Inhouse',
      key: '0-0-0',
      
      Merchants: [
        { title: 'abc', 

        key: '0-0-0-0' ,
      }


        
      ]
      
    }

]
},

];
and the data is coming from an backend

hsuanxyz pushed a commit to hsuanxyz/ng-zorro-antd that referenced this issue Aug 5, 2020
…Node (NG-ZORRO#2976)

refactor(module: tree): fix bugs and add extra functions

refactor(module: tree): fix spec

refactor(module: tree): add doc

refactor(module: tree): fix doc

refactor(module: tree): support getTreeNodeByKey

close NG-ZORRO#1998 close NG-ZORRO#2370 close NG-ZORRO#2655 close NG-ZORRO#2724 close NG-ZORRO#2273 close NG-ZORRO#1399 close NG-ZORRO#2208 close NG-ZORRO#2384 NG-ZORRO#2375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants