Thursday, November 3, 2016

APEX 4 to APEX 5 Migration Tip: Tree Regions

If you're moving your applications to APEX 5 you've probably read about deprecated features. One of the notes there is about the deprecation of jsTree Region.

It doesn't matter if you've turned on legacy JavaScript or jQuery Migrate you'll still get some errors by using old implementation so you have to move them to new APEX tree.

Most probably you'll get error in JS Console like this one:

The reason of this is that $.curCSS() method is removed in jQuery 1.8 and it's not added into jQuery Migrate library.

The next thing you'll probably notice is that there's no icons in new tree.

Old legacy tree:

New APEX tree:

FontAwsome Tree Icons

You can easily use FontAwsome icons there. To do this set Icon Type property to fa in Tree Attributes:

Next step is to modify SQL query of Tree region and set icon column to fa-folder-o

If you want a bit more, for example to have special icon for expanded folder you have to add additional CSS to you page (preferably to CSS file):

.a-TreeView .is-collapsible > .a-TreeView-content > span.fa:before{

After those modifications your tree should look like this:

APEX Tree Icons

There's also a way to use APEX font icons for the new APEX tree. Unfortunately, CSS classes are not included by default so you have to add it manually.

In case that you want to use APEX font icons you have to set Icon Type property to a-Icon:

Also you have to modify CSS class in icon column of source SQL query to icon-tree-folder:

The last thing is to add CSS classes (preferably to CSS file and not to inline CSS code page property):

  /* line 583, ../scss/core/IconFont.scss */
  .a-Icon.icon-tree-folder:before, > .a-TreeView-content > .a-Icon.icon-tree-folder:before {
    content: "\e0da";

  /* line 588, ../scss/core/IconFont.scss */
  .a-Icon.icon-tree-folder-open:before, > .a-TreeView-content > .a-Icon.icon-tree-folder:before {
    content: "\e0d7";

With APEX font icons your tree should look like this:

Returning selected node value dynamically

If you need to return node value dynamically without submitting page the easiest way to do it is to call $s function inside your SQL query:

Expand tree on page load

To expand tree on page load you have to call: 


where treeID is value of attribute property Static Tree ID of tree region.
Just put this code into page property Execute when Page Loads.

Edit: You can expand/collapse tree declaratively by using Dynamic Actions Expand/Collapse tree.


Tested on APEX