Loading ...
Sorry, an error occurred while loading the content.
 

TreeView and context menu

Expand Messages
  • Gabriele Farina
    Hi, I have to create a tree with leafs that shows a context menù dinamically filled with informations related to the leaf clicked. I don t know how to know
    Message 1 of 5 , Jun 29, 2006
      Hi,

      I have to create a tree with leafs that shows a context menù dinamically
      filled with informations related to the leaf clicked.
      I don't know how to know which leaf was clicked on (I have to retrieve
      the data assigned to the item). There is a way to do it ?

      gabriele
    • Adam Moore
      ... Gabriele, how are you defining the event handler that shows the context menu? You can access the node in the handler if you structure the handler
      Message 2 of 5 , Jun 29, 2006
        On Thu, Jun 29, 2006 at 06:26:59PM +0200, Gabriele Farina wrote:
        > Hi,
        >
        > I have to create a tree with leafs that shows a context men? dinamically
        > filled with informations related to the leaf clicked.
        > I don't know how to know which leaf was clicked on (I have to retrieve
        > the data assigned to the item). There is a way to do it ?
        >

        Gabriele, how are you defining the event handler that shows the context
        menu? You can access the node in the handler if you structure the handler
        correctly. Alternatively, if one of the properties assigned to the node
        is a unique id, pass that unique id to your handler and use
        getNodeByProperty to retrieve the node in the handler.

        http://developer.yahoo.com/yui/docs/treeview/YAHOO.widget.TreeView.html#getNodeByProperty

        -Adam
      • Nige White
        Here s a slightly modified version of how I do it (my getTreeNode() is in fact a method of my DDTreeView, so it doesn t need to be passed a tree ID). Your
        Message 3 of 5 , Jun 30, 2006
          Here's a slightly modified version of how I do it (my getTreeNode() is
          in fact a method of my DDTreeView, so it doesn't need to be passed a
          tree ID).

          Your ContextMenu has a contextEventTarget property which is the DOM
          element which received the right click event.

          I have a function which scans up the DOM ancestry from there until it
          finds a node.

          // The id of the tree is in myTreeId
          // The ContexMenu is in myContextMenu
          var target = getTreeNode(myTreeId,
          myContextMenu.contextEventTarget);

          ....

          /** Given a target DOM element, work up to find the containing Node's
          div,
          extract the node index, and look it up in the tree. */
          function getTreeNode(treeId, target)
          {
          var result = getAncestorWithClass(target, "div", "ygtvitem");
          if (result && result.id)
          {
          result = YAHOO.widget.TreeView.getNode(treeId,
          parseInt(/ygtv(\d+)/.exec(result.id)[1]));
          }
          return result;
          };

          /*
          Find the containing node with the given tag name and optionally a
          given class name
          */
          function getAncestorWithClass(node, tagName, className)
          {
          // Starting with the given node, find the nearest containing element
          // with the specified tag name and optionally class name.
          var lcTag = tagName.toLowerCase();
          while (node != null)
          {
          if (node.tagName != null && node.tagName.toLowerCase() == lcTag)
          {
          if (typeof(className) != "undefined")
          {
          if (YAHOO.util.Dom.hasClass(node, className))
          {
          return node;
          }
          }
          else
          {
          return node;
          }
          }
          node = node.parentNode;
          }
          return node;
          }

          Nige


          Gabriele Farina wrote:

          >Hi,
          >
          >I have to create a tree with leafs that shows a context menù dinamically
          >filled with informations related to the leaf clicked.
          >I don't know how to know which leaf was clicked on (I have to retrieve
          >the data assigned to the item). There is a way to do it ?
          >
          >gabriele
          >
          >
          >
          >
          >Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >_____________________________________________________________________
          >This message has been checked for all known viruses. Virus scanning
          >powered by Messagelabs http://www.messagelabs.com For more information
          >e-mail : hostmaster@...
          >
          >
          >


          _____________________________________________________________________
          This message has been checked for all known viruses. Virus scanning
          powered by Messagelabs http://www.messagelabs.com For more information
          e-mail : hostmaster@...
        • Nige White
          Just trigger the ContextMenu on the Tree id to use my method: myContextMenu = new YAHOO.widget.ContextMenu( contextMenu , {trigger:myTreeId}); ...
          Message 4 of 5 , Jun 30, 2006
            Just trigger the ContextMenu on the Tree id to use my method:

            myContextMenu = new YAHOO.widget.ContextMenu("contextMenu",
            {trigger:myTreeId});


            Gabriele Farina wrote:

            > How should I structure the hanlder to acces directly the node? I defined
            > an handler for every tree node, but is does not seems to me a good
            > solution.
            >
            > I'd likle to reproduce this behaviour: first of all I pregenerate the
            > context menu using custom markup. Then I intercept all the oncontextmenu
            > events that will be raised from the node into the tree. Based on the
            > node I enable/disable some menu items and I add aditional children to a
            > particular menu item.
            >
            > Gabriele
            >
            >
            > _____________________________________________________________________
            > This message has been checked for all known viruses. Virus scanning
            > powered by Messagelabs http://www.messagelabs.com For more information
            > e-mail : hostmaster@...



            _____________________________________________________________________
            This message has been checked for all known viruses. Virus scanning
            powered by Messagelabs http://www.messagelabs.com For more information
            e-mail : hostmaster@...
          • Gabriele Farina
            How should I structure the hanlder to acces directly the node? I defined an handler for every tree node, but is does not seems to me a good solution. I d likle
            Message 5 of 5 , Jun 30, 2006
              How should I structure the hanlder to acces directly the node? I defined
              an handler for every tree node, but is does not seems to me a good solution.

              I'd likle to reproduce this behaviour: first of all I pregenerate the
              context menu using custom markup. Then I intercept all the oncontextmenu
              events that will be raised from the node into the tree. Based on the
              node I enable/disable some menu items and I add aditional children to a
              particular menu item.

              Gabriele
            Your message has been successfully submitted and would be delivered to recipients shortly.