Started to get fed up sticking the same old javascript in my HTML header on lots of pages so I decided to make my report refresh call a little more generic… now I can just have it in my general JS library and call it however I want…
This is used with a background report page that is fed details by the calling page and the report region is displayed in the current page with no page submit. I generally use it for a summary report, with a ‘Details’ column link that drills down to a further report with more info. The report’s actually in another page but is displayed on the same page with no refresh.
With this function you input the page number of your target report, the name of the div that you want it displayed in on the current page and then an array of the items (could include column substitutions etc.) on the current page and an array of the items of the target page that need to be populated.
Very flexible now – you can derive the target page and even where it should be displayed, not necessarily from static calls but even by item values (checkboxes, LOVs, whatever you want!).
<script type="text/javascript">
<!--
function get_tasty_report(pTargetPage,
pRegionDiv,
pSourceItems,
pTargetItems){
if (pTargetPage == null) {
alert('No target page is defined');
return;
}
if (pRegionDiv == null) {
alert('No region div name is defined');
return;
}
var get = new htmldb_Get(null,$x('pFlowId').value,null,pTargetPage);
if (pSourceItems !== undefined || pTargetItems !== undefined) {
if (pSourceItems.length != pTargetItems.length) {
alert('Wrong number of arguments in call to get_tasty_report');
return;
}
for (var ii = 0; ii < pSourceItems.length; ii++) {
get.add(pTargetItems[ii], pSourceItems[ii]);
}
}
$x(pRegionDiv).innerHTML = get.get(null,'<ajax:TASTY_BODY>','</ajax:TASTY_BODY>');
}
//-->
</script>
You can see a little bit of rudimentary error handling in there that you can adapt if needed or simply remove – just there to throw things out to me when I was messing about with it.
Anyway, here’s a simple example using scott/tiger
http://apex.oracle.com/pls/otn/f?p=293:6
So all I’ve done is create a
SELECT *
FROM dept
WHERE deptno = : P5_DEPTNO
report region on page 5. I’ve also added a Display As Text(does not save state) item called P5_DEPTNO. Display condition is ‘Never’.
Next, I’ve copied the Printer Friendly template and called it AJAX Report. Then I replaced the ‘Body’ definition in my new template with…
<ajax:TASTY_BODY>
<div id="TASTY_BODY">#BOX_BODY#</div>
</ajax:TASTY_BODY>
and associated page 5 with the new AJAX Report template.
This (page 5) is the background page.
Now on page 6, I have a
SELECT *
FROM emp
report region.
I’ve also created a blank HTML region with a region source of…
<div id="my_div">
</div>
Then I’ve defined a ‘Department Details’ column with this as the link…
javascript:get_tasty_report('5','my_div',['#DEPTNO#'],['P5_DEPTNO'])
Note that the source items and target items are arrays – you can stick as many in there as you like, you can even target different pages and reports and display them in different regions on your page!