Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular material - Add branch lines for tree?

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 :

enter image description here

But how can I add branch lines ? something like (from here):

enter image description here

like image 462
d11 Avatar asked Sep 06 '18 10:09

d11


3 Answers

There are no such functionality out of the box. But you can apply it via CSS. There is a working example

like image 113
Aleksandr Neizvestnyi Avatar answered Sep 18 '22 22:09

Aleksandr Neizvestnyi


reply to the above answer the line breaks when two nodes expanded under one parent node

like image 43
umar suhail Avatar answered Sep 18 '22 22:09

umar suhail


enter image description hereenter image description here 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;
}
like image 36
hari prasad Avatar answered Sep 16 '22 22:09

hari prasad