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

using templates with findbytext

1 Answer 194 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 30 Aug 2016, 10:16 AM

Hi I have a treeview which is populated every time i select a row from grid which is a file name. I am currently adding the file size so I used a template - 

<script id="treeview-template" type="text/kendo-ui-template">
    <div class="layout-row">
           <div class="item-stylingsize">#: item.text #</div>
           <div class="item-stylingsize">#: item.size #</div>           
       </div>
    </script>

 

since adding this template -

              template: kendo.template($("#treeview-template").html()),
                dataTextField: "text",
                dataSource: tree,               
                select: onselect,                
                dataBound: function (e)
                {
                    try
                    {

                         // uid is just some text
                        var uid = returnUID();
                       
                        var treeview = $("#treeView").data("kendoTreeView");                        
                         var text = treeview.findByText(uid);                       
                        var itemroot1 = treeview.dataItem(text);                   

                        // expands to the correct node
                        treeview.expandTo(itemroot1);

                       // should select the correct node but does not
                        treeview.select(itemroot1);

}

 

My expandTo() function is not working because the findbytext() isnt working. 

A separate issue is the select() function does not select a node.

Any help would be appreciated

 

                        
             

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Sep 2016, 07:31 AM
Hello Paul,

I can assume that the issue is caused by two reasons:

1) All of the data is not fetched, which is returning undefined when an item is selected. Please, use the loadOnDemand property of the TreeView, and set it to false to load all of the data at once:

http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#configuration-loadOnDemand

2) The select method should be called before the expandTo method. When the loadOnDemand property is used the dataBound event will be fired a couple of times, which can cause errors, if the expandTo method is called first.

I made an example based on the provided code, and it is working as expected:

http://dojo.telerik.com/eyuhOK

I hope this will help you to achieve the desired result.

Regards,
Stefan
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
TreeView
Asked by
Paul
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or