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

Selecting Node On First Load Using HierarchicalDataSource

4 Answers 206 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 15 Aug 2012, 02:23 PM
Hello,

I am using the HierarchicalDataSource to bind data to my tree.
I would like to set a node selected when the data is returned from the server on the initial load.
I am currently trying the following.

Please note: in the initialization of tree, I am trying the set the attribute "selected" to the value of a property in my model object.
data = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "/Controller/Action",
            dataType: "json"
        }
    },
    schema: {
        model: {
            id: "Id",
            hasChildren: "HasChildren"
        }
    }
});
 
$("#tree").kendoTreeView({ 
    dataSource: data,
    dataTextField: "Alias",
    selected: "Selected"
});

Is this possible, what I am trying to achieve?


4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 20 Aug 2012, 07:15 AM
Hi Andrew,

I am afraid that there is no such configuration option provided by the TreeView. Also you cannot simply achieve this because the items cannot be expanded if they are not loaded. Nevertheless you can try to use the requestEnd event of the dataSource and the expand method of the TreeView to achieve this.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Andrew
Top achievements
Rank 1
answered on 20 Aug 2012, 07:43 AM
Hi Petur,

Thanks for getting back to me. However I am not sure that I understood your answer correctly. I wish to set the node selected and not expanded. This would always ensure that I have a node that can be set selected on the client side.

Or is there a way to manipulate the node style on first load, so I can give the node a selected style some how?

Best regards

Andrew
0
Petur Subev
Telerik team
answered on 23 Aug 2012, 08:25 AM
Hi Andrew,

Basically you can use the select method of the TreeView (you just need to pass the element you want to decorate as selected). To find the element you can use findByText method or findByUid. Again this logic should be executed when the request has finished (requestEnd).

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Andrew
Top achievements
Rank 1
answered on 23 Aug 2012, 08:37 AM
Hi Petur,

Thanks for getting back to me.
I am currently working on another project but I will give it a try when I start work on it again.

All the best

Andrew
Tags
TreeView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or