You must Sign In to post a response.
  • Category: ASP.NET

    Telerik Kendo Treeview binding

    Hi Telerik team,

    Looking forward a help for KendoTreeview binding using Typescript.

    Grabbing data from DB using WCf and getting till the ApiController.(getting the result here)

    Nee to pass the data from ApiController to typescript and from there to html page to bind the KendoTreeview.

    KendoTreeview should bind as each treenode should have a image depends on the status.

    Here is the resultset:

    level ID Name Status QID parentID
    1 1 AA 3 23 Null
    2 2 BB 3 24 23
    2 3 CC 3 25 23
    3 4 DD 3 26 24
    3 5 EE 3 27 25

    Here First name is the Main parent
    Second and third are the child parents.
    Forth one child of first child parent
    fifth one is child of second child parent.

    Could you please help me with a sample code?
  • #764459
    Hi chinnu,
    It depends on how you are binding your data i.e. binding to local data OR remote data OR OData.
    samples are as follows:
    http://demos.telerik.com/kendo-ui/treeview/local-data-binding
    http://demos.telerik.com/kendo-ui/treeview/remote-data-binding
    http://demos.telerik.com/kendo-ui/treeview/odata-binding
    For assigning image to a tree node in a kendo-ui treeview you can use following:
    function onSelectNode( e )
    {
    var dataItem = this.dataItem(e.node);
    dataItem.set("imageUrl", "someImage.png");
    }
    OR you can use a custom template [find demo here--> http://demos.telerik.com/kendo-ui/treeview/templates]

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764463
    Thanks Gurav.

    I am using WCF service to receive the data. Only one doubt here is I receive the data in the above format.

    How can I convert that to json format(as i mentioned last like main parent, child parents and child nodes).

    Please help me on this.

    Thank in advance.

  • #764464
    Why can not try to do the JSON Serialization and Deserialization

    Try the following class



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Runtime.Serialization.Json;
    using System.IO;
    using System.Text;
    public class JsonHelper
    {
    public static string JsonSerializer<T> (T t)
    {
    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
    MemoryStream ms = new MemoryStream();
    ser.WriteObject(ms, t);
    string jsonString = Encoding.UTF8.GetString(ms.ToArray());
    ms.Close();
    return jsonString;
    }

    public static T JsonDeserialize<T> (string jsonString)
    {
    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
    T obj = (T)ser.ReadObject(ms);
    return obj;
    }
    }


    By Nathan
    Direction is important than speed

  • #764467
    Thanks Gurav.

    Its working as expected.

    I am doing one more functionality for that I have a class called Details in that have members as level, ID, Name, Status, QID, parentID.
    Now From my resultset(mentioned above), I should return a List(which will have sublist as well) in which parentID null row will be the only one row.

    The rest rows should keep adding depends on their ParentID matches to the QID.
    And second and the third row should go as sublist for the first row.
    Forth row should go as child list for the first child list.
    And the same way fifth should go as sublist for second sub list.

    Here I am not using json.

    Please provide me a sample code. It is Urgent.

    Thanks in advance.

  • #764515
    Telerik is a third party tool and does not include with visual studio product, if you have purchase telerik product, it has its own support team to support all telerik product.
    or you can put this question on their support forum
    see below some links
    link for telerik general forum
    http://www.telerik.com/forums
    link for telerik Kendo-UI forum
    http://www.telerik.com/forums/kendo-ui

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764532
    Hi chinnu,

    For this latest functionality of Details class, you have to write a sql query in such a way that result will be retrieved as you mentioned or you can retrieve simple result set and process it before attaching it to Telerik Kendo Treeview. For this you can use Discionary of List i.e. Dictionary<string, List<string>>.

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments