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

Can't get the treview instance

2 Answers 102 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 25 Jul 2018, 04:54 AM

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 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 Jul 2018, 05:07 AM
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.
0
Luis
Top achievements
Rank 1
answered on 29 Jul 2018, 11:56 PM
Thanks. This has worked
Tags
TreeView
Asked by
Luis
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Luis
Top achievements
Rank 1
Share this question
or