ps0604
ps0604

Reputation: 1071

KendoTreeView: how to expand tree up to the first level?

In this jsfiddle I have a Kendo TreeView completely expanded using

treeView.expand(".k-item");

however what I'm looking for is to expand the tree only up to the first level (without changing the datasource). Is this possible?

HTML:

<div id="treeview"></div>

Javascript:

   var treeView = $("#treeview").kendoTreeView({
         dataSource: ds,
         dataTextField: ["Name"],     
    }).data("kendoTreeView");


    treeView.expand(".k-item");


    var ds = [
       {
        "Name": "Child 3",
        "items": [
            {
                "Name": "Leaf 1"

            },
            {
                "Name": "Leaf 2"

            },
            {
                "Name": "Leaf 3"

            },
            {
                "Name": "Leaf 4"

            },
            {
                "Name": "Leaf 5"

            },
                    {
                        "Name": "Child 4",
                        "items": [
                            {
                                "Name": "Leaf 8"

                            },
                            {
                                "Name": "Leaf 9"

                            },
                            {
                                "Name": "Leaf 10"

                            }
                        ]
                    }
             ]
        }

   ];

Upvotes: 2

Views: 2396

Answers (1)

CodingWithSpike
CodingWithSpike

Reputation: 43698

It's a little weird, but you can use the 'child' CSS selector to only select nodes that are 1 level deep:

treeView.expand("> .k-group > .k-item");

Upvotes: 4

Related Questions