Selecting Node On First Load Using HierarchicalDataSource

5 posts, 0 answers
  1. Andrew
    Andrew avatar
    9 posts
    Member since:
    Mar 2012

    Posted 15 Aug 2012 Link to this post

    Hello,

    I am using the HierarchicalDataSource to bind data to my tree.
    I would like to set a node selected when the data is returned from the server on the initial load.
    I am currently trying the following.

    Please note: in the initialization of tree, I am trying the set the attribute "selected" to the value of a property in my model object.
    data = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "/Controller/Action",
                dataType: "json"
            }
        },
        schema: {
            model: {
                id: "Id",
                hasChildren: "HasChildren"
            }
        }
    });
     
    $("#tree").kendoTreeView({ 
        dataSource: data,
        dataTextField: "Alias",
        selected: "Selected"
    });

    Is this possible, what I am trying to achieve?


  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 20 Aug 2012 Link to this post

    Hi Andrew,

    I am afraid that there is no such configuration option provided by the TreeView. Also you cannot simply achieve this because the items cannot be expanded if they are not loaded. Nevertheless you can try to use the requestEnd event of the dataSource and the expand method of the TreeView to achieve this.

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Andrew
    Andrew avatar
    9 posts
    Member since:
    Mar 2012

    Posted 20 Aug 2012 Link to this post

    Hi Petur,

    Thanks for getting back to me. However I am not sure that I understood your answer correctly. I wish to set the node selected and not expanded. This would always ensure that I have a node that can be set selected on the client side.

    Or is there a way to manipulate the node style on first load, so I can give the node a selected style some how?

    Best regards

    Andrew
  4. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 23 Aug 2012 Link to this post

    Hi Andrew,

    Basically you can use the select method of the TreeView (you just need to pass the element you want to decorate as selected). To find the element you can use findByText method or findByUid. Again this logic should be executed when the request has finished (requestEnd).

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Andrew
    Andrew avatar
    9 posts
    Member since:
    Mar 2012

    Posted 23 Aug 2012 Link to this post

    Hi Petur,

    Thanks for getting back to me.
    I am currently working on another project but I will give it a try when I start work on it again.

    All the best

    Andrew
Back to Top