2 Replies Latest reply on Jun 14, 2013 4:25 PM by carlos_tos

    tree - collapse and expand loses selection


      When a tree has a selected node and you collapse the tree either with the Collapse button or by manually closing the leafs, the selection reverts to the parent node.

      When you expand all the selected node is not updated.


      This makes the use of the tree for selection purposes confusing.


      In fact when you collapse the selection should be cleared otherwise the end user would think that the selected node is the parent and not a child.

      Selecting the parent may make sense to indicate that a selection is available inside this leaf but then a different color should be used to diferentiate a selection from a indication that a selection is available inside this leaf.


      You can see this problem here:


        • 1. Re: tree - collapse and expand loses selection
          Tom Petrus

          What you are describing is actually a configurable setting of the tree. It's just that the default action is set to select the parent node.

          From the docs of jstree:

          ui.selected_parent_close mixed

          This option specifies the behavior of the tree when a parent of a selected node is closed. The options are "select_parent" - which deselects the selected node and selects the closed one (similar to windows explorer), "deselect" - only deselects the selected node or false - does nothing.

          Default is "select_parent".


          So if you were to set it to deselect, it will simply deselect the node and your end result would be no selection.

          With the option set to false, the selected node will remain selected. So when you close the branch, no parent will be selected, and when opened again that last selected node will still be selected.


          You can set this option through javascript. For example, on your page I ran this in the console:

          $.tree.reference("#tree21227695007289061372").settings.ui.selected_parent_close = false


          If you were to give your tree region a static ID you could make the tree selection a bit easier by using this selector:

          "#static_region_id div.tree"
          • 2. Re: tree - collapse and expand loses selection

            Thank you this works for me in this situation and my problem is solved.


            But I think Apex should be improved sligthly on this issue.


            If I leave the default mode when I close the tree the root node becomes selected , when I then expand the node the root action stays selected.

            OK this is the default mode.

            Visually everything seems OK but there is an item which contains the selected node.

            If I do F5 the selected node changes again back to the child leaf. (Since the ITEM holding the selection ID was not updated. )


            This is because collapsing and expanding the tree does not trigger a change on the item.

            I tried with my real page and the process that saves the selected node is saving the child leaf which is not selected visually.


            This is strange to the end user, so I would probably have to patch in some aditional javascript so solve this.


            I think in future this type of functionality could be in Apex with an easy selection option otherwise tree looks like a patched in functionality.


            But maybe I am wrong.

            Thank you anyway.