📋 Smart Hierarchy Reports - Show Child Records Inside Parent Rows in Oracle APEX
🚩Introduction
In many Oracle APEX applications, data often has a parent-child relationship, such as departments and their employees, or orders and their order items. Showing this related data clearly, without making the page feel crowded, is important for a good user experience.
A useful approach is to show the child records right inside the parent row itself, when the user clicks a button. Instead of opening a separate region or navigating to another page, the child data simply expands within the same row. This keeps the report compact, easy to read, and gives users full control over what they want to see.
📑 Why This Approach Is Needed
In Oracle APEX applications, users often need to view related child records without losing context of the parent record they are looking at. If the child data is shown in a separate region or page, users have to keep switching back and forth, which can be confusing.
Showing child data within the parent row becomes useful when:
- Users want to see related details without leaving the current report
The report should stay clean and compact until the user needs more information
Parent and child data need to stay visually connected
Switching between separate regions or pages should be avoided
A simple click should be enough to view or hide the related data
This approach helps users stay focused, reduces page crowded, and makes it easier to understand the relationship between parent and child records in Oracle APEX.
👉 Use Case: Showing Child Region Within the Parent Row in Oracle APEX
Step 1:
--- DEPARTMENT ---
SELECT DEPTNO,
DNAME,
LOC,
'<span class="show_child" data-emp="' || DEPTNO || '">➕</span>' AS details
FROM DEPT;Step 3:
Create another region of type Interactive Report and set the source type as SQL query and copy the SQL Query below. We will be passing this page item in the sql query to fetch the respective child records.
--- EMPLOYEE REPORT ---
SELECT EMPNO,
ENAME,
JOB,
SAL,
DEPTNO
FROM EMP
WHERE DEPTNO = :P98_DEPT_NO; --Hidden Page item Step 4:
Step 5:
--- Inline CSS Code ---
#RG_EMP{
display: none;
}
.column-action-btn{
cursor: pointer;
}Step 6:
--- Function and Global Variable Declaration ---
function showDetail(el, depno) {
$s('P98_DEPT_NO', depno); -- Page Item
let btn = $(el);
let tr = btn.closest("tr");
if (tr.next().hasClass("detail_region")) {
tr.next().find(".slide-box").stop(true,true).slideUp(500, "swing", function () {
tr.next().remove();
});
return;
}
// Close & Remove other open rows
$(".detail_region").remove(); //Child Row ID
console.log(apex.item("P98_DEPT_NO").getValue());
apex.region("RG_EMP").refresh(); //Child Static ID
setTimeout(() => {
// Get content
let content = $("#RG_EMP").html();
console.log(content);
// Create row (content hidden initially)
let newRow = `
<tr class="detail_region">
<td colspan="99">
<div class="slide-box" style="display:none;">
\${content}
</div>
</td>
</tr>
`;
tr.after(newRow);
setTimeout(function() {
tr.next().find('.slide-box').stop(true,true).slideDown(500);
}, 300);
}, 1000);
}Step 6:
Now save and run the page, you will see the report rendered in the page.










Comments
Post a Comment