Browsing "Older Posts"

Browsing Category "Interactive Grid"

Interactive Grid: Validation - Check for duplicated column entries over all rows

Von Tobias Arnhold → 4.01.2020
I had this situation now a few times and was always to lazy to write it down. :/

During my last task within the fabe project I hat to create a validation to check for duplicated entries inside an Interactive Grid.
Whenever I add "None of the above" twice, an error should occur:
This blog post from Lino Schilde was a good start for my final solution:

Interactive Grid Validation
Validation of Type: PL/SQL Function (returning Error Text)
Code:
declare
  v_cnt number;
begin
 
-- check only if insert or update (not delete "D")
if :APEX$ROW_STATUS in ('C','U') then

  -- select only if the current row is set to Y
  -- positive result if one answer was set to Y
  select max(case when none_yn = 'Y' then 1 else 0 end)
  into v_cnt
  from answer
  where question_id = :P301_QUESTION_ID
  and answer_id != nvl(:ANSWER_ID,0)
  and :NONE_YN = 'Y';
 
  if v_cnt = 1 then
    return 'Another answer was already set up with "None of the above". You need to change and save it first.';
  end if;

end if;
end;

My solution used a "max" aggregation within a "case when" trick to get the right result.

Maxime Tremblay gave me a really important tip:
If I add more then one row through the IG and press save. The validation is not gone be triggered.

To fix that you to add a unique index:
create unique index ANSWER_UK1 on ANSWER (
  case when NONE_YN = 'Y' then QUESTION_ID end
);



--
--

Tip of the day
All those meeting clients (Skype, Zoom, Hangouts ...) can also be used for APEX friends and beer meetups. #beer #orclapex

Interactive Grid: After Update Trigger

Von Tobias Arnhold → 3.29.2020
If you want to run a process after the "Interactive Grid" successfully updated all rows you can achieve this with a dynamic action. This can be necessary if you need to update certain columns calculated over several row in the same table you updated within the grid. Problem is to refresh the related data inside the grid as well.

Example:
You edit 3 rows for column A within your grid.
The grid updates column A row by row.
After that an update process should calculate a new result for column B which includes the data from all those updated 3 rows in column A.

Column A
row 1: 150 
row 2: 200
row 3: 100

Column B includes the sum of  column A
row 1: 450 
row 2: 450 
row 3: 450  

All you need to do is to define your Grid like this:
Interactive Grid > Advanced > Static ID: igYourGrid

Dynamic Action Event: Save [Interactive Grid]
Selection Type: Region
Region: Your Grid
Event Scope: Static

Action: Execute PL/SQL Code
custom_pkg.after_update_process;

Action: Execute Javascript Code
var model = apex.region("igYourGrid").widget().interactiveGrid("getViews").grid.model;
model.fetchRecords(model._data);




Be aware that the custom_pkg.after_update_process; process may not be executed when JavaScript errors occur.

This solution is completely dynamic and does not require a page submit.

--
--

Tip of the day
Since all conferences get cancelled worldwide join those online conferences instead:
ACE's at Home: https://itoug.it/aces-at-home/ (March 31th '20)
APEX@Home: https://asktom.oracle.com/pls/apex/f?p=100:551:::NO:551:P551_CLASS_ID:744 (April 16th '20)

Interactive Grid - Column stretching

Von Tobias Arnhold → 12.19.2018
Since APEX 18.1 you can define the stretch behavior per column.

You can choose between 3 different options:

Use Report Setting
The column will use the Stretch Report Setting set by the End User to define if the column should stretch or not.
In APEX 18.1 you have a new option to let the end user decide if the columns should be stretched or not.
This option effects all columns by default.

Never
The column will not stretch and always just use the width specified. This is useful for columns with short content like Yes/No or Numbers.
This option will over rule "Use Report Setting" and is really good for link columns or as the documentation says: short content columns.

Always
The column will always stretch, irrespective of the Stretch Report Setting set by the End User.


Results can look slightly different:


Imho: Small enhancement with huge impact.