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

kendo.Data.Model instance in a HierarchicalDataSource for bindng TreeView

1 Answer 249 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Stefan Söderberg
Top achievements
Rank 1
Stefan Söderberg asked on 13 Feb 2013, 08:29 AM
Hi, I am having problems using an instance of a kendo.Data.Model in a HierarchicalDataSource.

I tried this simple model for a folder object:

var folderModel = kendo.data.Model.define({
    id: "Id",
    hasChildren: "HasChildren",
    children: "Children",
    fields: {
        Id: { editable: false, nullable: true },
        Name: { validation: { required: true} },
        ParentFolderId: { editable: false, nullable: true }
    }
});

Then created a simple data source using that as the model:

var folderStore = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "/Folders/",
            dataType: "json",
            type: "POST"
        },
    },
    schema: {
        model: folderModel
    }
});

The datasource is then used to bind a TreeView.

$(function () {
    $("#folderTreeView").kendoTreeView({
        dataSource: folderStore,
        dataTextField: ["Name"]
    });
});

This fails and the treeview is not bound.

However, it does work if I use an inline approach when defining the datasource:

var folderStore = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "/Folders/",
            dataType: "json",
            type: "POST"
        },
    },
    schema: {
        model: {
            id: "Id",
            children: "Children",
            hasChildren: "HasChildren"
        }
    }
});

Even if I simplify the model down to:

var folderModel = kendo.data.Model.define({
    id: "Id",
    children: "Children",
    hasChildren: "HasChildren"
});

I cannot use it in the datasource.

Must be missing something here, please advice. Would like to use the model for CRUD operations elsewhere and want to use the same model in the treeview.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Feb 2013, 07:25 AM
Hello,

The HierarchicalDataSource uses kendo.data.Node which extends kendo.data.Model so it should be used in this case:

var folderModel = kendo.data.Node.define({
    id: "Id",
    hasChildren: "HasChildren",
    children: "Children",
    fields: {
        Id: { editable: false, nullable: true },
        Name: { validation: { required: true} },
        ParentFolderId: { editable: false, nullable: true }
    }
});
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Hierarchical Data Source
Asked by
Stefan Söderberg
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or