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

What shall I use, having a flat table, showing as a treeview

1 Answer 135 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Iwhp
Top achievements
Rank 1
Iwhp asked on 10 Aug 2012, 02:20 PM
I have the following data in a database:
RowId, Text, ParentRowId
1, "Root", {null}
2, "Animal", 1
3,."Cat", 2
3, "Dog", 2

This data shall be shown by the TreeView.

I'd like to return the data as JSON,  then bind the data to the TreeView.
What's the "best" way?

1 Answer, 1 is accepted

Sort by
0
Iwhp
Top achievements
Rank 1
answered on 14 Aug 2012, 06:32 AM
I came up with the following, using a HierarchicalDataSource:

var childrenDataSource = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: function (options) {
                return kendo.format("../api/hierarchytree/{0}", options.id);  // only return child elements of a specific node
            }
        }
    },
    schema: {
        model: {
            hasChildren: "hasChildren",
            id: "id"
        }
    }
})


// Setup data source, that will get the [root] elements for the treeview
var rootDataSource = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "../api/hierarchytree" // only return root elements 
        }
    },
    schema: {
        model: {
            hasChildren: "hasChildren",
            id: "id",
            children: childrenDataSource
        }
    }
});
Tags
TreeView
Asked by
Iwhp
Top achievements
Rank 1
Answers by
Iwhp
Top achievements
Rank 1
Share this question
or