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

How to add nodes programatically when using tree view?

2 Answers 201 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Barani
Top achievements
Rank 1
Barani asked on 11 Dec 2012, 09:32 PM
Hi,

We are planning to use kendo tree view for displaying a context path as a tree structure, something like

Field value would look something like A/B/C/D

I will split this string using / to get each nodes, I am trying to form tree as below,

A
-B
--C
---D

I am not sure whats the best way to achieve this.

Is it better to form tree datasource object manually and provide it as a datasource?  Or is it good to use append method to append the tree. The problem with append method is that I don't see id for parent node hence I m not sure how to append child corresponding to a particular parent. Can you please let me know the best possible route?

Thanks,
Barani

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 13 Dec 2012, 01:28 PM
Hi Barani,

As I understood it the data consists of one string field that contains information about the path.
In that case I suggest to parse the string manually and build a hierarchical JSON structure. As an example:
data = [{
    text: "A", items: [{
        text: "B", items: [{
              text: "C"
        }]
    }]
}]

After that you can pass the generated structure as a dataSource of the TreeView. Please check this sample.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Barani
Top achievements
Rank 1
answered on 14 Dec 2012, 01:27 AM
Thanks for your response.

Thanks,
Barani
Tags
TreeView
Asked by
Barani
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Barani
Top achievements
Rank 1
Share this question
or