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

Initial settings/params for HierarchicalDataSource/TreeView

2 Answers 496 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 22 Jun 2012, 02:38 PM
Hi,

Based on your beta demo here: http://demos.kendoui.com/beta/web/treeview/odata-binding.html 

I have put together the following:

var Folders = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: function(opt) {
                    if(opt.UID == undefined) opt.UID = 0;
                    return kendo.format("/api/GetFolders/{0}",opt.UID)
                    },
                type: "GET",
                dataType: "json"
            }
        },
        schema: {
            model: {
                hasChildren: function() {
                    return true;
                },
                id: "UID",
                children: Folders
            }
        }
    });


    $("#testTree").kendoTreeView({
        dataSource: Folders,
        dataTextField: ["Title"]
    });

As you can see I am using a fairly ugly hack for the initial UID setting. But it works with my data.

Since there is no documentation yet (that I can see) can you advise if there is a better way of doing this? In particular I'd like to have more than one TreeView on screen (sharing a single data source if possible) and be able to specify at runtime where each TreeView should 'start'.

Thank,

Mark.

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 27 Jun 2012, 02:44 PM
Hi Mark,

Your code looks OK, as a slightly different approach I would recommend the following configuration:
var homogeneous = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "example",
            dataType: "json"
        }
    },
    schema: {
        data: "employees",
        model: {
            id: "employeeId",
            hasChildren: "hasChildren"
        }
    }
});
 
$("#treeview").kendoTreeView({
    dataSource: homogeneous,
    dataTextField: "employeeName"
});

The "hasChildren " field indicates if the current model has children:
{
    "employees": [{ "employeeName": "Andrew", "employeeId": 1, "hasChildren": true }]
}

When the HierarchicalDataSource is homogeneous only one level is enough to be defined, however you will still have to use the valid approach that is used to construct the url.

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
foo
Top achievements
Rank 1
answered on 10 Sep 2012, 07:41 AM
the treeview (as in your remote with hirachical data example) works great, but when I wrap it into a viemodel, it stops working.
does it mean the recommended way is to use a regular datasource and use the id from the treeview to select an editable (data-bound form) item?
Tags
Hierarchical Data Source
Asked by
Mark
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
foo
Top achievements
Rank 1
Share this question
or