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

Issue with externally defined datasource vs. inline datasource

1 Answer 66 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Trenton
Top achievements
Rank 1
Trenton asked on 10 Jul 2014, 07:47 PM
I can't figure out what I am doing wrong with this.

Treeview code with inline dataSource defined - this works fine.

var lobTv = $("#linesOfBusiness").kendoTreeView({
            select: function (e) {
                var tree = this;
                var src = tree.dataItem(e.node);
                jobOwnerId = src.LobId;
                isParent = src.HasChildren;
            },
            change: function (e) {
                appsDataSource.read();
            },
            dataSource: {
                transport: {
                    read: {
                        url: apiUrl + "Lob"
                    }
                },
                schema: {
                    model: {
                        id: "LobId",
                        hasChildren: "HasChildren"
                    }
                }
            },
            loadOnDemand: false,
            dataTextField: "LobName"
        });

If I move the dataSource definition out to its own declaration:

var lobDataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: apiUrl + "Lob"
                }
            },
            schema: {
                model: {
                    id: "LobId",
                    hasChildren: "HasChildren"
                }
            }
        });

and change the treeview to use the defined datasource:

var lobTv = $("#linesOfBusiness").kendoTreeView({
            select: function (e) {
                var tree = this;
                var src = tree.dataItem(e.node);
                jobOwnerId = src.LobId;
                isParent = src.HasChildren;
            },
            change: function (e) {
                appsDataSource.read();
            },
            dataSource: lobDataSource,
            loadOnDemand: false,
            dataTextField: "LobName"
        });

The data is no longer displayed in the treeview.  When I look at the call/response in firebug, the data is returned correctly.

What am I missing?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 11 Jul 2014, 11:43 AM
Hello Trenton,

The TreeView uses a HierarchicalDataSource, so changing the kendo.data.DataSource to kendo.data.HierarchicalDataSource should solve the problem.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
Trenton
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or