Adding the expand icon through javascript

3 posts, 1 answers
  1. Peter Ryckaert
    Peter Ryckaert avatar
    16 posts
    Member since:
    Jul 2006

    Posted 30 Jul 2010 Link to this post

     

    Here some piece of code... Where I load through javascript and my own webservice call a treeview. In my collection of objects, I know
    how many children I have for each item. If obj.Children > 0 I would like to show the Expand Icon. I don't see in the documentation how I can do that, the expand thing is only shown if I seed the expand mode WebService, but in this case it complains no WebService is configured... So it would be cool if I could find a solution.

     

    if (obj.Children > 0) {

     

        node.set_expandToSOMETHING
    }

     

     

    var tree = $find(this.treeviewId);
    var parentNode = null;
    if (parentId != 0) {
        parentNode = tree.findNodeByValue(parentId);
    }
    for (var x = 0; x < result.Result.length; x++) {
        var obj = result.Result[x];
        var node = new Telerik.Web.UI.RadTreeNode();
        node.set_text(obj.Display);
        node.set_value(obj.KeywordId);
        node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.ClientSide);
        if (obj.Children > 0) {
            node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.ClientSide);
        }
        if (parentId != 0) {
            parentNode.get_nodes().add(node);
        } else {
            if (obj.ParentKeywordId == 0) {
                tree.get_nodes().add(node);
            } else {
                var parentNode = tree.findNodeByValue(obj.ParentKeywordId);
                parentNode.get_nodes().add(node);
            }
        }
    }
    tree.commitChanges();
    if (parentId != 0) {
        parentNode.set_expanded();
    }
  2. Answer
    Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 03 Aug 2010 Link to this post

    Hello Peter Ryckaert,

    Just a thought:
    - Why don't you use our built-in LoadOnDemand functionality? Here is a nice article (it's first of a whole section) that will give you a better detail: http://www.telerik.com/help/aspnet-ajax/tree_databindingloadondemand.html

    If you insist following the current direction, here is what you can do to achieve this requirement:
    1. You can set the ExpandMode of the nodes that have children to WebService and create a fictive WebService on the server, just to avoid the error message you said you are getting;
    2. Then you can handle the ClientNodeExpanding client-side event, in which you will:
     - call the function that should call the real webService and populate the node;
     - switch node's mode to ClientSide;
     - expand the node so the children become visible;
     - and cancel the initial and still following Expand event ("args.set_cancel(true);" should do it).

    This should workaround it, but still my advice for you is to consider using our default LoadOnDemand functionality!

    Hope this is helpful for you!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Peter Ryckaert
    Peter Ryckaert avatar
    16 posts
    Member since:
    Jul 2006

    Posted 04 Aug 2010 Link to this post

    Okido, Thank you, I will give a try...

    About the LoadOnDemand, I tested it with TabPanels and Radviews and Grids, and it's a complete disaster.. (At my point of view... No viewstate, no renderings of not requested panels, (Even if not rendered on client, it's still rendered on the server)  As I told before the loadondemand should only load when we demand, and should maintain no state by reloading at every postback... I tryed al types of Grid loadings and finally I had to go through manual load and binding... Has any setting we set on a control at design time will be registered at each postback... Even if not rendered, and certainly not requested    :)

    So I don't think I'll lose my time to implement the loadondemand on the treeview even if it's working differently :-)
Back to Top