using templates with findbytext

2 posts, 0 answers
  1. Paul
    Paul avatar
    24 posts
    Member since:
    May 2016

    Posted 30 Aug Link to this post

    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>           


    since adding this template -

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

                             // 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

                           // should select the correct node but does not



    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



  2. Stefan
    Stefan avatar
    195 posts

    Posted 01 Sep Link to this post

    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:

    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:

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

    Telerik by Progress
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Back to Top