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

2 posts, 0 answers
  1. Iwhp
    Iwhp avatar
    40 posts
    Member since:
    Dec 2009

    Posted 10 Aug 2012 Link to this post

    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?
  2. Iwhp
    Iwhp avatar
    40 posts
    Member since:
    Dec 2009

    Posted 14 Aug 2012 Link to this post

    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
            }
        }
    });
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top