Javascript > Function and global variable declaration:
var l$Tree;
function addFeedback(pMsg){
if($.browser.ie){
$("#P38_FEEDBACK").val(pMsg + "\n\r" + $("#P38_FEEDBACK").val());
}else{
$("#P38_FEEDBACK").val(pMsg + "\n" + $("#P38_FEEDBACK").val());
}
};
function searchTree(pWhat,pHow){
$.tree.reference(l$Tree).search(pWhat,pHow);
addFeedback("Searching the tree for " + pWhat + " yields nodes:");
$(".search").each(function(){
addFeedback("Matched node: " + $(this).parent().attr('id') + $(this).text());
});
};
function treeOnload(){
l$Tree = $("#emptree div.tree");
$.extend($.expr[':'], {
ciContains: function(elem, i, match) {
return $(elem).text().toUpperCase().indexOf(match[3].toUpperCase()) >= 0;
}
});
$.tree.reference(l$Tree).settings.data.async = false;
$.tree.reference(l$Tree).settings.callback.onselect = function(NODE, TREE_OBJ){
addFeedback("Selected node: " + $(NODE).attr('id') + $("a:first", NODE).text());
$("#P38_SELECTED_EMP").val($(NODE).attr('id'));
$("#report_emp").trigger("apexrefresh");
};
$.tree.reference(l$Tree).settings.callback.onopen= function(NODE, TREE_OBJ) {
addFeedback("Opened node: " + $(NODE).attr('id') + $("a:first", NODE).text());
$("#P38_SELECTED_EMP").val($(NODE).attr('id'));
};
$.tree.reference(l$Tree).settings.callback.onclose= function(NODE, TREE_OBJ) {
addFeedback("Closed node: " + $(NODE).attr('id') + $("a:first", NODE).text());
$("#P38_SELECTED_EMP").val($(NODE).attr('id'));
};
};
function resetAndOpenToLevel ( pTree, pMaxLevel ) {
apex.jQuery.tree.reference(pTree).close_all();
$("ul", pTree).each(function ( index ) {
if ( $(this).parents("ul").length <= pMaxLevel ) {
apex.jQuery.tree.reference(pTree).open_branch(this);
};
});
};
Onload:
treeOnload();
CSS Inline:
.search{
border-style:solid;
border-width:1px;
border-color:green;
}
REPORT: EMP Details
The report template is the "attribute - values pair".
select empno, ename, job, hiredate, sal, comm, deptno, mgr
from emp
where empno = :P38_SELECTED_EMP
Page items to submit:
P38_SELECTED_EMP
Static id:
report_emp
Dynamic action on the "Search tree" button: fires on click.
A true action of type "Execute javascript". Does not fire on page load.
searchTree($v("P38_SEARCH_TREE"), $("#P38_SEARCH_CASE_0").prop("checked") ? "ciContains" : null);
This will call the "searchTree" function defined in the "Function and global variable declaration" and provide the value of the search field as a parameter.
The thing that makes search work in this function is just this line:
$.tree.reference(l$Tree).search(pWhat, pHow);
The other lines are simply feedback, but it provides an example of how you can read the matched elements in javascript.
The pHow parameter is the pseudo-selector used for the search operator. Default it is "contains", and this is not case-sensitive. To make it case-sensitive a new pseudo-class has been added, ciContains, to be able to perform a case-insensitive contains operation. The inline-if construct will set pHow to ciContains when the checkbox has been checked. Note that an apex checkbox item will be a fieldset element, which in turn holds the actual checkbox. The _0 suffix will target the checkbox directly. Using $v on the fieldset will return the value of the checkbox as defined in the item's lov settings.
Dynamic action on the "Reset and Open to Level" button: fires on click.
A true action of type "Execute javascript". Does not fire on page load.
resetAndOpenToLevel(l$Tree, $v("P38_OPEN_LEVEL"));
P38_OPEN_LEVEL is the select list. Select a level and click the button to first reset the tree, and then have it opened up to nodes of the selected level. A level which is larger than the maximum level will simply expand the tree completely.
REPORT: Employees - select a node
select null select_node, empno, ename from emp order by empno
Column "SELECT_NODE": column link defined:
- Link Text: Select Node
- Link Attributes: onclick="return false;" class="treeselect" data-node-id="#EMPNO#"
- Target: URL
- URL: #
Dynamic action "select node from report"