This is a migrated thread and some comments may be shown as answers.

TreeView Nodes Without Children Show as Expandable

9 Answers 1160 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 2
Walter asked on 24 Apr 2018, 11:18 PM

My JSON data is generated by a recursive data structure. Where a queue may contain a queue of queues. In the case of a child queue being empty I'd to not show it as expandable. Reworking the data sources is not possible. I'm looking for a pointer on how best to tackle this. I'm building a webified version of a ClickOnce WinForms app. See attached.

 

 

9 Answers, 1 is accepted

Sort by
0
Walter
Top achievements
Rank 2
answered on 25 Apr 2018, 09:28 PM

I've been able to programmatically style the TreeView Template (code snippets below) but yet to find he hook to that expand/collapse glyph since it's class name includes a indexing number. Still open to suggestions. 

in queues.component.scss:
    .hit {
       border: 5px solid black;
     }

in queues.component.html:
        <ng-template kendoTreeViewNodeTemplate let-dataItem>  
            <span [ngClass]="iconClass(dataItem)"></span>            
            <span>{{dataItem.Caption}}</span>                
            <span class="custom-right">[{{dataItem.Count}}]</span>       
        </ng-template>


in queues.component.ts:
public iconClass(node: IQueue): any {
          // this detects those nodes that have children nodes
          if (node.Children.length) {
            return 'hit';
          }
     

0
Walter
Top achievements
Rank 2
answered on 25 Apr 2018, 09:30 PM
Results do far. Correctly identifying only three queues that have children.
0
Walter
Top achievements
Rank 2
answered on 25 Apr 2018, 09:34 PM
Results so far. Correctly identifying only three queues that have children. Error occurred on previous post trying to attach graphic.
0
Walter
Top achievements
Rank 2
answered on 25 Apr 2018, 09:36 PM

Sorry for empty post. This site is having an issue with pix upload.

 

"Oh, no! 
Something's not right,
but we're sorting it out."

0
Walter
Top achievements
Rank 2
answered on 26 Apr 2018, 12:10 PM
0
Svet
Telerik team
answered on 26 Apr 2018, 03:09 PM
Hi Walter,

Thank you for the provided screenshots.

I am not sure that I understand the issue.

We can control the expand/collapse icon with the logic inside the hasChildren function as demonstrated in the following sample plunker:

https://plnkr.co/edit/hva8vS2PHO7VFpso7drh?p=preview

Check the "Sofas" node. It has items, which are an empty array:

public data: any[] = [
    {
        text: 'Furniture', items: [
            { text: 'Tables & Chairs' },
            { text: 'Sofas', items: [] },
            { text: 'Occasional Furniture' }
        ]
    },
    {
        text: 'Decor', items: [
            { text: 'Bed Linen' },
            { text: 'Curtains & Blinds' },
            { text: 'Carpets' }
        ]
    }
];

but we are not displaying the collapse icon because of the following logic:

public hasChildren = (item: any) => item.items && item.items.length > 0;

I hope this helps. In case I am missing something please provide some more details as to what needs to be achieved.

Regards,
Svetlin
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Walter
Top achievements
Rank 2
answered on 26 Apr 2018, 04:19 PM

Svetlin,

My plunker above has similar data and similar results to your dojo example. I believe I understand the relationships. My question has more to do with strong typing, but just now I see it's not an issue with accessing node properties. To troubleshoot I changed the code:
public hasChildren = (item: IQueue) => false;           // item.Children && item.Children.length > 0;

and always the nodes have the expand/collapse icon.

0
Walter
Top achievements
Rank 2
answered on 26 Apr 2018, 04:26 PM

Svetlin,

Please, also see Support Ticket ID:1164129 which has more information. Just opened this morning.

0
Walter
Top achievements
Rank 2
answered on 26 Apr 2018, 09:58 PM

kendoTreeViewHierarchyBinding was the culprit; I removed it an it all worked as expected

 

I closed the support ticket.

Tags
General Discussions
Asked by
Walter
Top achievements
Rank 2
Answers by
Walter
Top achievements
Rank 2
Svet
Telerik team
Share this question
or