APEX – Dynamic Actions with Report Region

In many scenarios it would be nice if we can provide some dynamic actions to report (classical) region, which can be handled via Ajax calls, rather then submitting a whole page  – these actions could include:

  • Delete a line in report
  • Edit a one item on one line
  • Adding a line  from other pop-up page
  • Change order of lines
  • And and many others similar

Consider report like this one:

Here we want two have two Ajax actions: first when ‘X‘  is clicked then we want this  line to be deleted; second, when we change quantity on a line, this action should be stored to the  database.

For Column QTY we will use custom column formatting (Column Format/Html Expression), rather then predefined column display type (Display As):

Last column in the table will have a link displaying  X (Link Text: X, Link Attributes: style="color:red; font-weight:bold; text-decoration:none"  ) and linked to  URL: javascript:removeItem(#ID#).

Then we have do define 2 hidden page items (used to submit values in Ajax calls), and also Ajax Callback processes as shown below:

The Ajax Callback processes are fairly straightforward – they should be of Type: “PL/SQL anonymous block” , with  Process Point : “OnDemand …”.   “Update Quantity” process just runs simple update query:

And “Delete line” process runs simple delete query:

Last piece is  Javascript code to glue this all together – JS should be put in region definition in Header and Footer/ Header Region

Some details about this JS code:

lines 2-6 – since we want to update just individual lines via Ajax calls,   we want to prevent default behaviour of input, that all form is submitted (if there are aby visible page items on page then there is a form element encapsulated in a form). However we want to keep possibility to fire change event by pressing Enter. The only easy way I can think of was firing blur event – line 5– if you know better way how to do it. please leave a comment here.

lines 12 and 24 – this initiates Ajax requests to our processes – note that name of the process has to be specified in 3rd parameter in form ‘APPLICATION_PROCESS=Process name’.  Any page items needed for page process has to be submitted with that requests – add method should be used.

lines 17 and 28 – when Ajax call is done we need to reload report – this can be done easily by APEX JS function $a_report, however we need to know id of region, where report is rendered.  If  we render script in region header, like in this case, we can use replacement string #REGION_STATIC_ID# as done on lines 11 and 23.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">