user3863616
user3863616

Reputation: 195

Oracle APEX - how to read a cell from interactive grid

The same question once again but with (I hope) better explanation:

I created the most simple case:

  1. An Interactive Grid IG with data source EMP ( table with 14 records contains Ename, Job, HireDate, Salary etc. etc.)
  2. Text field P7_ENAME

After running it looks like below:

enter image description here

What I would like to do is to copy Ename from selected record of IG to P7_ENAME field . I found several tutorials (text and video) how to do it. Most of them suggest to create dynamic action SelectionChange on IG and when TRUE add a JavaScript code something like below:

var v_ename;
model = this.data.model;
v_ename = model.getValue( this.data.selectedRecords[0], "Ename");
apex.item( "P7_ENAME" ).setValue (v_ename);

and the second step is to create another action: Refresh. So finally I have a dynamic action with two steps : the first one is a Java script code and the second refresh function on my P7_ENAME field.

Sounds simple and it is simple to repeat/implement. A guy (I suppose) from India published a video on YouTube (https://www.youtube.com/watch?v=XuFz885Yndw) which I followed and in his case it works good. In my case it simple does not work - field P7ENAME is always empty, no errors appears. Any idea why ? Any hints, suggestion ?

thanks for any help

K.

Upvotes: 0

Views: 10993

Answers (1)

cengiz sevimli
cengiz sevimli

Reputation: 2105

The best way to debug and achieve what you are trying to do is as follows:

  1. create the Dynamic action with the following setup:

    -when -> selection change[interactive grid],
    -selection type -> region, region -> your IG region, 
    -client side condition -> javascript expression: ```this.data.selectedRecords[0] != undefined```
    
  2. First action of the true of the DA with the type: execute javascript code and fire on initialization is turned on, code: console.log(this.data.selectedRecords);

  3. Run your page, and check the browser console. You should see an array of columns when you select a record from that IG as follows:enter image description here

Find in that array, which sort number of the array contains the data that you want to use for the page item. Let's say I want the 3rd element which is "2694" then I should change my dynamic action's execute javascript code to:

    var value = this.data.selectedRecords[0][2];
    apex.item( "P7_ENAME" ).setValue (value);

The last thing I should do is add another true action (and the refresh action at the end) to the same dynamic action with type 'SET VALUE' and 'PLSQL EXPRESSION' as type, put :P7_ENAME in the expression, items to submit P7_ENAME and affected element: item / P7_ENAME as follows: enter image description here

Upvotes: 5

Related Questions