Page 1 of 1

Extract all leafs or External Nodes of Selected task

Posted: Tue Jul 16, 2019 9:25 am
by rahulranjan
Hi
Is it possible to get all the leafs nodes from selected task .

Re: Extract all leafs or External Nodes of Selected task

Posted: Tue Jul 16, 2019 10:37 am
by pmiklashevich
Please open https://bryntum.com/examples/scheduler/tree/ demo, select a resource (Terminal A for example), and run in console:
result = []; scheduler.selectedRecord && scheduler.selectedRecord.traverse(node => node.isLeaf && result.push(node));
Check the `result`
result.map(node => node.name)
// ["Gate 1", "Gate 2", "Gate 3", "Gate 4", "Gate 5", "Gate 6", "Gate 7", "Gate 8", "Gate 9", "Gate 10"]
Docs here:
https://www.bryntum.com/docs/scheduler/#Common/data/mixin/TreeNode#property-isLeaf
https://www.bryntum.com/docs/scheduler/#Common/data/mixin/TreeNode#function-traverse

Re: Extract all leafs or External Nodes of Selected task

Posted: Tue Jul 16, 2019 12:44 pm
by rahulranjan
Thanks it works
One more question can i get all the parents of a task for example

N1
->N2
->N3
->T4

I want all the parents of T4 and it should return N1,N2,N3 including root node

Re: Extract all leafs or External Nodes of Selected task

Posted: Tue Jul 16, 2019 1:02 pm
by pmiklashevich
Please select Gate 1 and run in console:
parent = scheduler.selectedRecord && scheduler.selectedRecord.parent;
result = [];
root = scheduler.resourceStore.rootNode;
while (parent) {
    result.push(parent);
    parent = parent.parent;
}
result.map(node => node === root ? 'root' : node.name)
//["Gates 1 - 5", "Terminal A", "Kastrup Airport", "root"]