CirclonGroup / angular-tree-component

A simple yet powerful tree component for Angular (>=2)
https://angular2-tree.readme.io/docs
MIT License
1.1k stars 492 forks source link

The filtering function of angular tree-component does not apply to multiple child nodes. #869

Open kimselim opened 4 years ago

kimselim commented 4 years ago

There are several child nodes in one node as shown below. According to the manual in the tutorial, grandchild2-1-1 is not searched, only child2 is searched. Is it impossible to search with the functions in the manual?

image

`filterTree() { let foundResults: TreeNode[] = [];

this.treeComponent.treeModel.filterNodes((node: TreeNode) => {
  const nodeName = node.data.name;
  const searchValue = this.searchChartWord;
  const nodeFound = nodeName.includes(searchValue);

  if (nodeFound && node.hasChildren) {
    for (let child of node.children) {
      if(child.hasChildren){
        foundResults.push(node);
      }
    }
    foundResults.push(node);
  }
  return nodeFound;
});

foundResults.forEach((item) => {
  item.children.forEach((child) => {
    child.show();
    child.ensureVisible();
  });
});

}`

code: <tree-root #tree [nodes]="nodes" [focused]="true"> <ng-template #treeNodeTemplate let-node="node" let-index="index"> <input class="pt-1"type="checkbox" [indeterminate]="node.data.indeterminate" [checked]="node.data.checked"> <span class="pl-1" (click)="treeMembers(node.data)">{{node.data.name}}</span> </ng-template> </tree-root>