0
votes

I have a kendo Treeview which is showing the parent nodes but the child nodes are not seen. Can anyone tell me where am i going wrong. I am new to this concept. I followed the below link but its not working. http://demos.telerik.com/kendo-ui/treeview/remote-data-binding

 function treeView() {
        var treeM = new kendo.data.HierarchicalDataSource({
            schema: {
                data: function (response) {
                    console.log("response" + JSON.stringify(response));
                    var rdata = {};
                    if (response.d) {
                        rdata = JSON.parse(response.d);
                    }
                    else {
                        rdata = response;
                    }
                    return rdata; // ASMX services return JSON in the following format { "d": <result> }.
                },
                model: {
                    hasChildren: true,
                    id: "ID",
                    expanded: true,
                    fields: {
                        ID: { editable: false, nullable: false, type: "string" },
                        LINK: { editable: true, nullable: true, type: "string" },
                                          },
                },
            },
            transport: {
                read: {
                    url: "/getParent",
                    contentType: "application/json; charset=utf-8",
                    type: "POST",
                    datatype: "json"
                },
                parameterMap: function (data, type) {
                    if ((type == "update") || (type == "create") || (type == "destroy")) {
                        console.log('parameterMap:');
                        return JSON.stringify({ "LinksJson": data });
                        console.log(JSON.stringify(data));
                    } else {
                        return data;
                    }
                }
            }
        });

                 $("#treeview1").kendoTreeView({
            dataSource: treeM,
            dataValueField: "ID",
            dataTextField: ["LINK","Name"]
        });

    }

    $("#treeview").on("click", ".k-in", function (e) {
        var tree = $("#treeview").data('kendoTreeView');
        tree.toggle($(e.target).closest(".k-item"));
    });


    $(document).ready(function () {
        treeView();
    });

Service:

 [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string getParent()
    {
        using (var context = new Data.Entities())
        {
            IQueryable<ERPv2.Data.Links> dataQuery = from x in context.Links
                                                          where x.ParentID == 68
                                                         select x;
            var newQry = dataQuery.AsEnumerable().Select(c => new
                         {
                             ID = c.ID,
                              Name = c.Name,
                             Children = HasChildren(231)
                         });
            JavaScriptSerializer JSON = new JavaScriptSerializer();
            return JSON.Serialize(newQry);

        }
    }




      [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public bool HasChildren(int ID)
        {
            using (var context = new Data.Entities())
            {
                IQueryable<ERPv2.Data.Links> dataQuery = from x in contextLinks
                                                             where x.ParentID == ID
                                                             select x;

                return dataQuery.AsEnumerable().Any();
            }
        }
2

2 Answers

0
votes

Even when you try to view the child nodes, it will try to call getLinks and not the getreports. From what i have seen , you should have only one method for getting parent and children. Can be an array inside each parent node. Can you combine the data from GetReports method inside getlinks itsself and give it a shot.

0
votes

You should try and get this working here with hardcoded values and then do configure with services. http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#configuration-dataSource