Forum Stats

  • 3,722,431 Users
  • 2,244,306 Discussions
  • 7,849,829 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Apex Interactive grid save selected row in page item

PamNL
PamNL Member Posts: 637 Gold Badge
edited March 2019 in APEX Discussions

I tried several blogs, but I'm obviously missing a step here ..

I have two interactive grids on my page. My idea is that you should selected one row from each grid and I want to do some processing on that (without actually submitting the page).

So as soon as you select a row, I want to store a value from the selected row.

I tried adding a dynamic action on APEX$ROW_SELECTOR with event Selection Change (interactive Grid). But how should I program the Action?
I tried SetValue with Javascript Expression (among other things)

apex.item ("P2_SELECTED_MB").setValue ("...")

(First with a static value to see if anything happens at all. After that I wanted to figure out how to pass a value from the grid.

I know you can select more records, so this will not work if you select multiple records, but it should work at least when you select one. I found several things on other blogs like

https://ruepprich.wordpress.com/2017/03/23/bulk-updating-interactive-grid-records/

But that should fire when you save I guess? So I created a button with a dynamic action with the javascript. Again .. at first I simply hardcode a stringvalue, but still nothing seems to happen (at least the page item is not showing any values on the page).

I also tried printing a message just to see if anything happens

apex.message.clearErrors();

apex.message.showPageSuccess ("At least something happens!");

But that also does not appear .. I'm sure what I want to achieve is pretty simple, so I hope you gurus may help me out here ..

pastedImage_1.png

Best Answer

  • Franck N
    Franck N Member Posts: 1,016 Silver Trophy
    edited February 2019 Accepted Answer

    Hi,

    here you go:

    step 1:

    create your item which will store the selected Element.

    step 2: create a dynamic action on Selection Change [Interactive Grid]---> selection type Region--> your IG Region Name

    add this code on the true Action of type javascript:

    var i, selectedIds = ":", model = this.data.model; for ( i = 0; i < this.data.selectedRecords.length; i++ ) {      selectedIds += model.getValue( this.data.selectedRecords[i], "EMPNO") + ":"; } $s("P6_SELECTED", selectedIds);

    Notes EMPNO is the Name of your Column ID so replace it accordingly.

    P6_SELECTED is the Name of your item which will store the IDs from selecting the check boxes.

    regards,

    Franck

    PamNL

Answers

  • Franck N
    Franck N Member Posts: 1,016 Silver Trophy
    edited February 2019 Accepted Answer

    Hi,

    here you go:

    step 1:

    create your item which will store the selected Element.

    step 2: create a dynamic action on Selection Change [Interactive Grid]---> selection type Region--> your IG Region Name

    add this code on the true Action of type javascript:

    var i, selectedIds = ":", model = this.data.model; for ( i = 0; i < this.data.selectedRecords.length; i++ ) {      selectedIds += model.getValue( this.data.selectedRecords[i], "EMPNO") + ":"; } $s("P6_SELECTED", selectedIds);

    Notes EMPNO is the Name of your Column ID so replace it accordingly.

    P6_SELECTED is the Name of your item which will store the IDs from selecting the check boxes.

    regards,

    Franck

    PamNL
  • John Snyders-Oracle
    John Snyders-Oracle Member Posts: 1,349 Employee
    edited February 2019
    PamNL wrote:I tried several blogs, but I'm obviously missing a step here ..I have two interactive grids on my page. My idea is that you should selected one row from each grid and I want to do some processing on that (without actually submitting the page).So as soon as you select a row, I want to store a value from the selected row.

    Can I assume that you want to "do some processing" in response to the user clicking a button?

    Rather than constantly keep hidden page item up to date with the current selection I recommend a click DA on the button. Add an Execute JavaScript Code action.

    That code will get the current selection from both IG regions.

    var r1Records = apex.region("r1").call("getSelectedRecords");

    var r2Records = apex.region("r1").call("getSelectedRecords");

    It will verify that there is just one record selected in each if that is desired.

    If (r1Records.length === 1 && r2Records.length === 1) {

        /*doSomething*/

    } else {

       apex.message.alert("Select one row from each report.");

    }

    Use model.getValue to extract the key and put it in hidden page item as Franck showed.

    Now you can execute PL/SQL code or call a process using apex.server.process.

    The advantage to listening for selectionchange events on each IG region is to enable/disable the button so it is only enabled when exactly one row in each IG is selected. For that you can use the Selection Change [Interactive Grid] DA event. You can listen on document or "body" so that the one DA handles selection change for both IG regions. For example Selection type = jQuery Selector, jQuery Selector = body.

    A dynamic action on APEX$ROW_SELECTOR is meaningless. The grid row selection header is very special and doesn't fire any events. The grid and ig fire selectionchange events but you would need to listen for them on the respective widget element or an ancestor of it.

    Regards,
    -John

    PamNL
  • user5734696
    user5734696 Member Posts: 1 Green Ribbon

    Hello everyone,

    This is very helpful code. I've managed to create an item, e.g. P6_SELECTED which is dynamically set to one of the fields when I click a record on the IG. I can display this item's value in a text field on the same page. All very well so far.

    However, I can't seem to make use of this item as a variable in a SQL query nor a list in a marquee in a region within the same page. The value just comes out blank.

    On a different page where I have a Master-Detail using IR, I have followed a near identical process to make of use of an item and pass its value to a list in a marquee in another page, which works fine. (only difference being this item's value is passed via URL from another page, rather than being generated via JavaScript on the same page).

    Is there something about an item set on a IG or some parameter that I have missed?

  • user5734696
    user5734696 Member Posts: 1 Green Ribbon

    On the SQL query, I had to put the item in the "Items to Submit" field in properties. That sorted that one out.

    However, I'm still scratching my head as to why the marquee list isn't picking up the item being passed in the URL. See attached image for the list target settings. P4_ACCOUNT_ID is the page item that I'm setting dynamically using the DA with Javascript.


Sign In or Register to comment.