2

I used angular 7 and ngx-treeview component .

I have used a config of decoupleChildFromParent= true.

From this treeview we only get child tree value. I want to get the parent node value.

this my html code :

  <ng-template #itemTemplate let-item="item" let-onCollapseExpand="onCollapseExpand" let-onCheckedChange="onCheckedChange">
      <div class="form-inline row-item">

        <i *ngIf="item.children" (click)="onCollapseExpand()" aria-hidden="true" class="fa" [class.fa-caret-right]="item.collapsed"
          [class.fa-caret-down]="!item.collapsed"></i>
        <div class="form-check">
          <input type="checkbox" class="form-check-input" [(ngModel)]="item.checked" (ngModelChange)="onCheckedChange()" [disabled]="item.disabled"
            [indeterminate]="item.indeterminate" />
          <label class="form-check-label" (click)="item.checked = !item.checked; onCheckedChange()">
            {{item.text}}
          </label>

        </div>
      </div>
    </ng-template>

    <div class="row">
      <div class="col-6">
        <div class="form-group">
          <div class="d-inline-block">
            <ngx-treeview [items]="items" [itemTemplate]="itemTemplate" (selectedChange)="onSelectedChange($event)">
            </ngx-treeview>
          </div>
        </div>
      </div>

    </div>

I used onSelectedChange function with this code :

 onSelectedChange(downlineItems: DownlineTreeviewItem[]) {
            this.rows = [];
            downlineItems.forEach(downlineItem => {
                const item = downlineItem.item;
                const value = item.value;
                const texts = [item.text];
                let parent = downlineItem.parent
                while (!isNil(parent)) {
                    texts.push(parent.item.text);
                    parent = parent.parent;
                }
                const reverseTexts = reverse(texts);
                const row = `${reverseTexts.join(' -> ')} : ${value}`;
                this.rows.push(row);
                this.rowsSelect=value;
            });
        }

when I check the parent check box, selectedChange event fired with empty array of values.

I would like to retrieve the value of selected parent when none of the child is selected

franco
  • 1,829
  • 6
  • 42
  • 75
  • You can try this project https://github.com/leovo2708/ngx-treeview/blob/master/src/demo/product/product.component.html – Chunbin Li May 06 '19 at 15:42
  • thank you for your response, I followed this example. but this example only allows to get the value of the child node using onSelectedChange function and my goal is to get the value of the parent node – franco May 07 '19 at 07:40

1 Answers1

-1
import {TreeviewHelper} from 'ngx-treeview';

TreeviewHelper.findParent(rootItem, item);
pzaenger
  • 11,381
  • 3
  • 45
  • 46
mayeen
  • 1