ORACLE-APEX 22.1 - Update select list value based on Interactive Grid changes

I have a Form and an Interactive Grid in a modal page. The Form populate a collection and the Interactive Grid calls the values from the collection. There are two select lists in the form with year values (P99_AN_INICIAL and P99_AN_FINAL). While the user change their values, the Interactive Grid is updated. For example: P99_AN_INICIAL = 2010 and P99_AN_FINAL = 2015, so the Interactive Grid will have 5 rows. If the user delete the first row (2010), the select list P99_AN_INICIAL must update its value to 2011.

List of Values of P99_AN_INICIAL:

SELECT MIN_YEAR - LEVEL AS display_value,
       MIN_YEAR - LEVEL AS return_value
FROM   (SELECT NVL(:P99_AN_INICIAL, MIN(AN_CALENDARIO)) AS MIN_YEAR
        FROM   TB_BEM
        WHERE  ID_PHAROS = :P99_LAST_ID_PHAROS
          AND  ID_CASO = :GLOBAL_CASE_ID
          AND  ID_PESSOA = :GLOBAL_PERSON_ID
        )
WHERE  :P99_ID_BEM IS NOT NULL
CONNECT BY LEVEL <= 20

UNION ALL

SELECT (EXTRACT(YEAR FROM SYSDATE) - 20 + LEVEL) AS display_value,
       (EXTRACT(YEAR FROM SYSDATE) - 20 + LEVEL) AS return_value
FROM   dual
WHERE  :P99_ID_BEM IS NULL
CONNECT BY LEVEL <= 40

ORDER  BY return_value ASC;

I created a DA in Interactive Grid so the value of P99_AN_INICIAL could be updated just after the row be deleted.

Event: Save [Interactive Grid]

True Action 1:

DECLARE
  v_min_year NUMBER;
BEGIN
  SELECT MIN(n001)
  INTO v_min_year
  FROM apex_collections
  WHERE collection_name = 'EDITAR_BEM';
   
  APEX_UTIL.SET_SESSION_STATE('P99_AN_INICIAL', v_min_year);
  
END;

True Action 2:

Refresh page item P99_AN_INICIAL.

The problem: the value of the select list is not displayed in the form after the row delete. Anyone could help me with that, please?

Upvotes: 0

Views: 67

Answers (1)

Koen Lostrie
Koen Lostrie

Reputation: 18640

In current version of APEX it's not possible to refresh a page item itself with a dynamic action. Page items are created in the DOM at page rendering time only. However, page items of type "Select List" can be refreshed by using the "Cascading List Of Values" attribute of a select list. This makes a select list dependent on the value of a "Parent Item".

Consider the following example. There is a select list on the EMP table that is refreshed on change of the page item P150_DEPT. By setting the "Parent Item(s)" attribute of the select list to P150_DEPT, this value will be submitted to the session and only the employees in the current department are shown.

enter image description here

The changes in your dynamic action to make this work should be (I have not tested this)

  • For True Action 1: set "Items to Return" to P99_AN_INICIAL. This will set the value in the DOM causing the select list to refresh.
  • Remove True Action 2.

Note:

Unrelated to this question, but in your code you're using

APEX_UTIL.SET_SESSION_STATE('P99_AN_INICIAL', v_min_year);

While this works perfectly it's important to know that APEX_UTIL.SET_SESSION_STATE will sometimes commit as explained is this blog therefore I rarely use it and stick to bind variable syntax.

:P99_AN_INICIAL := v_min_year;

It's not advised to mix bind variable syntax and APEX_UTIL.SET_SESSION_STATE within the same process.

Upvotes: 1

Related Questions