Thursday, February 25, 2010

APEX Refresh Classic Report Region AJAX style

We often have the need to refresh a classic report region, AJAX style. It is straightforward to get a refresh link on the page. I used to just build a link using $a_report (the APEX built-in for doing partial page refresh on classic reports). But I have found it is better to create a javascript function in the region header or footer. This has the advantage that you can call it from a button on the page, or from any location on the page, not just from within the header or footer itself. If you put the following

<script type="text/javascript">
function c2RefreshTasks(){ 
  pId = '#REGION_ID#';   // report region id
  $a_report(pId.substring(1),'1','15');  // APEX built-in
  }
</script>

This allows me to put a link anywhere on the page

<a href="javascript:c2RefreshTasks();">refresh tasks</a>

I can also create a standard button anywhere on the page that calls this javascript.

I recently also had the need to pop a new window (child), add a task in that child window, close the child and then refresh the task region in parent window. It turned out to be easy...

Just create the APEX child window that does the insert/update.&nbsp; Have it branch to a page (e.g. P99). On P99, put the following in the HTML header

<script type="text/javascript">
 // important to have the try because the parent window might have changed...
{ try {
  window.opener.c2RefreshTasks();
  }
  catch(err) {
  window.close(); 
  }
}
  window.close();
</script>

8 comments:

Neelesh Shah said...

Very useful Anton. Thanks

vamshi said...

"Just create the APEX child window that does the insert/update.  Have it branch to a page (e.g. P99). On P99, put the following in the HTML header"

I am very new to APEX, How do I create a child window in APEX ?

Anton Nielsen said...

You use a bit of javascript to open a child window. For example,

javascript:popupURL('f?p=&APP_ID.:3');

will open a new window and load page 3. You can put that javascript in the URL portion of a button or a link anywhere in the builder.

Bill said...

Hi Anton,
What about a LightBox? I tried the code but it did not work probably because this is a jQuery lightBox.
Thanks for the help. BillC

chemise abercrombie said...

very nice post!and i like very much!

Lunette de soleil Cartier said...

vous fashion.thank pour le partage

spanish interpreters said...

thanks for this helpful post...



spanish interpreters

spanish interpreters said...

thanks for this helpful post...



spanish interpreters