RadTreeView OnClientNodeCollapsing

4 posts, 0 answers
  1. Graham
    Graham avatar
    28 posts
    Member since:
    Feb 2011

    Posted 03 Jun 2012 Link to this post

    I have a RadTreeView on a page which I have coded as follows:

    <telerik:RadTreeView ID="radTreeView" runat="server" Width="100%" AutoGenerateColumns="true" OnNodeClick="radTreeView_OnNodeClick">
    <
    WebServiceSettings Path="BuildTrgMP.aspx" Method="GetChildNodes" />

    </telerik:RadTreeView>

    I have coded the GetChildNodes webservice call on the server side and this all works fine: when the user clicks a + on the tree, the little whirly appears which the webservice is called to populate the tree, which it does so correctly.
    What I want to do is the opposite situation: when the user clicks a - on the tree, I want it to invalidate everything under that node such that the next time the + is clicked, the webservice is again called so that the list is updated from the database.
    At the moment clicking the + just reopens the list which has previously been cached in the browser and the webservice is not called to refill the list.
    How do I use OnClientNodeCollapsing (or any other approach) to invalidate the list such that pressing + causes the webservice to be called again ?

    Thanks
    Graham Plowman

  2. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 04 Jun 2012 Link to this post

    Hi Graham,

     
    You can Clear the nodes and reset the expand mode as it is done in the code below: 

    function OnClientNodeCollapsing(sender, args) {
     
               sender.trackChanges();
               args.get_node().get_nodes().clear();
               args.get_node().set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.WebService);
               sender.commitChanges();
           }

    Hope this will help you.

    Kind regards,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Graham
    Graham avatar
    28 posts
    Member since:
    Feb 2011

    Posted 04 Jun 2012 Link to this post

    Thanks Plamen.
    I've tried that but it doesn't fully work.
    If I start at the top of the tree and expand nodes to the lowest level eg:

    - TMP Number 1
    ...- Module1
    ......- CLO1
    .........- MLO1
    ...+ Module2
    ...+ Module3
    ...+ Module4

    If I then close the entire structure by clicking the - next to TMP Number 1, followed by pressing its +, then I click Module1 (not its +) I get:

    - TMP Number 1
    ...+ Module1
    ...Module2
    ...Module3
    ...Module4  
    ...+ Module1
    ...Module2
    ...Module3
    ...Module4  

    In other words, the structure is duplicated. If I repeat the close of the root element, then its + and Module1 I get the tree repeated three times.
    If I click the + signs to re-expand the tree, all works fine and the tree is populated from the database.
    There seems to be a problem with clicking on the actual item text.

    If I take out the code you suggested, the duplication no longer happens, but I'm back to my original problem of the tree being cached and not updating from the database.

    I'm using 2011.1.519.35

    I have no code other than the web service code populating the list:

    public static RadTreeNodeData[] GetChildNodes(RadTreeNodeData node) {

    int langId = Convert.ToInt32(HttpContext.Current.Session["LangId"]),

    orgId =

    Convert.ToInt32(HttpContext.Current.Session["OI"]);

    KuriousDataContext db = new KuriousDataContext();

    // If the node is the root TMP, the node value is the Id of the TMPNode

    // record it represents, otherwise, it is the Id of the TMPNodeLink record

    // whose child node id points at the node.

    List<TMPNodeLink> childNodeList = db.FindTMPNodeLinks(Convert.ToInt32(node.Value)).ToList();

    // Work out the node level we are looking at

    int level = Convert.ToInt32(node.Attributes["NT"]) + 1;

    // Get the first item of the element list which is the element name

    var titleElement = db.FindTMPElement(Convert.ToInt32(HttpContext.Current.Session["OI"]), level, CConstants.TMPPR_TITLE);

    List<RadTreeNodeData> result = new List<RadTreeNodeData>();

    foreach (TMPNodeLink nodeLink in childNodeList) {

    RadTreeNodeData childNode = new RadTreeNodeData();

    TMPNodeData nodeData = db.FindTMPNodeData(nodeLink.TMPNodeId, titleElement.Id, langId);

    childNode.Text = (nodeData ==

    null ? "[Not Found]" : nodeData.ValueText);

    childNode.Value = nodeLink.Id.ToString();

    if (db.HasAnyChildTMPNodes(nodeLink.Id)) {

    childNode.ExpandMode =

    TreeNodeExpandMode.WebService;

    }

    else {

    // childNode.ExpandMode = TreeNodeExpandMode.ClientSide;

    }

    //childNode.ImageUrl = NodeTypeImageURL((int)_node.NodeTypeId);

    childNode.Attributes.Add(

    "NT", nodeLink.TMPNode.NodeTypeId.ToString());

    result.Add(childNode);

    }

    node.ExpandMode =

    TreeNodeExpandMode.WebService;

    return result.ToArray();

    }


  5. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 07 Jun 2012 Link to this post

    Hello Graham,

     
    It looks like this behavior is by the session in the GetChildNodes() method. I am attaching a sample project based on our online demo where is shown show we recommend implementing the Web Service binding in RadTreeView.

    Hope this will help you.

    Regards,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top