I've created a simple tree with Angular material tree :
https://stackblitz.com/edit/angular-exhejg-vx5i7c?file=app/tree-dynamic-example.html
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl" >
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding >
<button mat-icon-button ></button>
{{node.item}}
</mat-tree-node>
<mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding >
<button mat-icon-button
[attr.aria-label]="'toggle ' + node.filename" matTreeNodeToggle>
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
{{node.item + '2'}}
<mat-progress-bar *ngIf="node.isLoading"
mode="indeterminate"
class="example-tree-progress-bar"></mat-progress-bar>
</mat-tree-node>
</mat-tree>
It looks like :
But how can I add branch lines ? something like (from here):
There are no such functionality out of the box. But you can apply it via CSS. There is a working example
the line breaks when two nodes expanded under one parent node
I am using mat-nested-tree. step-1 Add a left border to both the li. step-2 Add another div inside li. apply below css see image...
.setBorder{
border-bottom: 1px solid black;
width: 22px;
height: 0px;
position: relative;
left: 0px;
top: 0px;
}
.borderMain{
border-left: 1px solid black;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With