2
votes

I'm using PrimeNG treetable component and I want to get all the children of a node when I click on getChildrens button near that node.

Also, I want to get all the parents of that node when I click the getParents button near the same node.

The goal is to give a different style to the children and parents of the node once I select the appropriate button.

Is PrimeNG treetable offer that functionnality to get all the children and parents of a node ?

1
Have you tried to use onNodeExpand event ? Can you create a StackBlitz please ?Antikhippe

1 Answers

0
votes
    getParent(node, arr) {
        if (node && node.label) {
          let result;
          arr.unshift({
            key: node.tag,
            value: node.label,
            data: node.data
          })
          
          if (node.parent) {
            result = this.getchildren(node.parent, arr)
          } else {
            result = arr 
          }
          return result
        } else {
          this.initdata.ancestorValue = []
          arr = []
        }
    
      }
      getchildren(node, arr) {
        if (node && node.label) {
          let result;
          arr.unshift({
            key: node.tag,
            value: node.label,
            data: node.data
          })
          if (node.parent) {
            result = this.getParent(node.parent, arr)
          } else {
            result = arr 
          }
          return result
        }
        return arr      
    
      }

console.log(this.getParent(event.node,[])