Can't get the treview instance

3 posts, 0 answers
  1. Luis
    Luis avatar
    3 posts
    Member since:
    Dec 2017

    Posted 24 Jul 2018 Link to this post

    I'm creating a treeview in MVC using the TreeViewBuilder. like this

     Html.Kendo().TreeView().Name("TreeViewTemplateBiding")....

    I need to get access to the treeview instance in a script. It's not an event, so I can't rely on the tree passing the instance to my function.

    I'm trying, as instructed:

    var myTree = $("#TreeViewTemplateBiding").data('kendoTreeView')

    This does not work, it returns 'undefined'. In fact I can see that $("#TreeViewTemplateBiding") has no data at all.

    Please assist.

     

  2. Eyup
    Admin
    Eyup avatar
    4012 posts

    Posted 26 Jul 2018 Link to this post

    Hi Luis,

    I've tried the following configuration to test this behavior and it works as expected on my side:
    @(Html.Kendo().TreeView()
            .Name("TreeViewTemplateBiding")
            .Items(treeview =>
            {
                treeview.Add().Text("Furniture")
                    .Items(root =>
                    {
                        root.Add().Text("Tables & Chairs");
                        root.Add().Text("Sofas");
                        root.Add().Text("Occasional Furniture");
                    });
     
                treeview.Add().Text("Decor")
                    .Expanded(true)
                    .Items(root =>
                    {
                        root.Add().Text("Bed Linen");
                        root.Add().Text("Throws");
                    });
     
                treeview.Add().Text("Storage")
                    .Items(root =>
                    {
                        root.Add().Text("Wall Shelving");
                        root.Add().Text("Kids Storage");
                        root.Add().Text("Baskets");
                        root.Add().Text("Multimedia Storage");
                    });
            })
    )

    Added a button to call the logic:
    <button onclick="buttonClick();">Access TreeView</button>

    And this is the script logic:
    <script>
        function buttonClick() {
            var treeView = $("#TreeViewTemplateBiding").data().kendoTreeView;
            treeView.expand(treeView.items()[0]);
        }
    </script>

    Please try this configuration and verify that it works properly on your side, too.

    Regards,
    Eyup
    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.
  3. Luis
    Luis avatar
    3 posts
    Member since:
    Dec 2017

    Posted 29 Jul 2018 in reply to Eyup Link to this post

    Thanks. This has worked
Back to Top