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

TreeView in cell template

2 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ICT
Top achievements
Rank 1
Iron
ICT asked on 30 Jul 2020, 10:38 AM

Hi,

I'm trying to put a Kendo TreeView in a Cell Template.

The rendering is ok, but i cannot expand it ALWAYS when i click, sometimes i can but it starts flickering.

Any suggestion?

Here my template

<ng-template
          kendoGridCellTemplate
          let-dataItem
          let-columnIndex="columnIndex"
          let-rowIndex="rowIndex"
        >
<div *ngIf="column.isTree">
            <kendo-treeview
              [nodes]="columnsService.parse(dataItem[column.field])"
              textField="text"
              kendoTreeViewExpandable
              kendoTreeViewHierarchyBinding
              [isExpanded]="true"
              childrenField="items"
            >
            </kendo-treeview>
          </div>
        </ng-template>

Thanks,

B

2 Answers, 1 is accepted

Sort by
0
ICT
Top achievements
Rank 1
Iron
answered on 30 Jul 2020, 12:02 PM

[isExpanded]="true" is not correct, i removed it, same issue.

 

B

0
Dimitar
Telerik team
answered on 03 Aug 2020, 06:58 AM

Hello Benedetta,

The described undesired behavior is most probably due to binding the nodes property of the TreeView to a function returning a new array instance on every change detection cycle. I could reproduce it in this simplified example. The tree is flickering as the nodes are recreated anew every time change detection passes.

You have two options to resolve the issue:

  • Bind the TreeView to a static array instance - there's no need to parse the data on every change detection cycle. Parsing the data as often could also lead to performance issues if the parsed data set is very large. So you could create a wrapper component for the TreeView which accepts the raw stringified data, parse it only on component init, and pass the processed data to the TreeView.
  • Use the TreeView trackBy prop. It allows the component to track the nodes by a specified field, so it won't recreate all the nodes even if a new data array instance is passed on each change detection cycle. Here's an example.

Let me know if further information on the topic is required.

Regards,
Dimitar
Progress Telerik

Tags
Grid
Asked by
ICT
Top achievements
Rank 1
Iron
Answers by
ICT
Top achievements
Rank 1
Iron
Dimitar
Telerik team
Share this question
or