treeoracle-apexhierarchy

In Oracle Apex, how do i set value to page item on a selected tree region row?


I'm encountering an issue with my Oracle APEX application. When I click on a row on my global tree region, I want to assign the value of a column (The "ID") from the clicked row to a page item (P0_SELECTED) but as of yet have not been able to achieve this.

I have assigned the value of ID as the 'Node value column' in the attributes of the tree hierarchy. I have also selected node page item as P0_SELECTED. I have also tried to do a set value dynamic action on event tree node selection, but with no success. I just want the page item to display the ID when a row is selected.


Solution

  • The easiest way which I also use to set the selected tree row's Node Value Column attribute to a page item is as follows:

    1. Create a dynamic action of event 'Selection Change [Tree]'
    2. Create a true action of type 'Execute Javascript Code' with JS code:
    var id = apex.jQuery("#your_treeregions_static_id div[role='tree']").treeView("getSelectedNodes")[0].id;
    $s('YOURPAGEITEM', id);  
    

    If you still have problems, I' suggest using a timeout and a try catch statement just to make sure the tree region is ready. In that case, your code would be:

    setTimeout(function () { 
        try{
         var id = apex.jQuery("#your_treeregions_static_id div[role='tree']").treeView("getSelectedNodes")[0].id;
         $s('YOURPAGEITEM', id);  
        }catch(e){
         console.log(e);
        }
    }, 50);