Forum Stats

  • 3,781,240 Users
  • 2,254,495 Discussions
  • 7,879,622 Comments

Discussions

How to access elements in SingleRowView of an Interactive Grid?

John like many others
John like many others Member Posts: 110 Blue Ribbon
edited Jun 26, 2020 9:10AM in APEX Discussions

Hello

I can easily access the records and elements of an Interactive Grid in record like this:

var activeRegion = $('#ActiveTab').find('.apex-rds-selected').prop('id').replace('_tab', '');

var trigger = $(this.triggeringElement);

var rowId = trigger.closest('tr').data('id');

// Get grid from active region

var grid = apex.region(activeRegion).widget();

// Get model of curent grid

var model = grid.interactiveGrid('getViews', 'grid').model;

// Get active record

var record = model.getRecord(rowId);

// Get element value of record

var pc_id = model.getValue(record, 'PC_ID');

...

I even found an option to check if the Grid is in record or single view mode:

var singleRowMode = grid.interactiveGrid("getViews").grid.singleRowMode;

What I don't know is how access the elements displayed in the single view mode (like the textfield). Using the operations above on record view shows me an error. This is obvious to me because singlerow view is not based on an array.

So the question is: How I can access the elements (set/get values of elements) in single row view mode?

Thanks in advance for any help!

KeyserGabriel Guzman

Best Answer

  • Keyser
    Keyser Member Posts: 829 Bronze Trophy
    edited Jun 26, 2020 6:24AM Accepted Answer

    it's the same model, only the view has changed (i think)

    I don't know what element is triggering your code but I don't think this...

    var trigger = $(this.triggeringElement);

    var rowId = trigger.closest('tr').data('id');

    ...will get you what you want when you are in single record view mode

    I tried this...

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getActiveRecordId()

    and it works if you are in edit mode...(using empno as my primary key column)

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getActiveRecordId()

    "7499"

    but if you aren't in edit mode it returns nothing, so instead I tried this...

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getSelectedRecords()

    seeing as we are in single row view mode, it gives you the current visible row

    pastedImage_4.png

    but that's positional (same with getContextRecord())  so if someone moves a column then it may break your code, so you could get the position from...

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getColumns()

    there maybe something more appropriate, have a look at what is available...(change "theIG" to your static ID)

    apex.region("theIG").widget().interactiveGrid("getViews", "grid")

    you can then use the primary key column value to access the model as before (i think)

    EDIT : and please change you username to something more recognisable than "3052157"

    Gabriel Guzman

Answers

  • Keyser
    Keyser Member Posts: 829 Bronze Trophy
    edited Jun 26, 2020 6:24AM Accepted Answer

    it's the same model, only the view has changed (i think)

    I don't know what element is triggering your code but I don't think this...

    var trigger = $(this.triggeringElement);

    var rowId = trigger.closest('tr').data('id');

    ...will get you what you want when you are in single record view mode

    I tried this...

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getActiveRecordId()

    and it works if you are in edit mode...(using empno as my primary key column)

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getActiveRecordId()

    "7499"

    but if you aren't in edit mode it returns nothing, so instead I tried this...

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getSelectedRecords()

    seeing as we are in single row view mode, it gives you the current visible row

    pastedImage_4.png

    but that's positional (same with getContextRecord())  so if someone moves a column then it may break your code, so you could get the position from...

    apex.region("theIG").widget().interactiveGrid("getViews", "grid").getColumns()

    there maybe something more appropriate, have a look at what is available...(change "theIG" to your static ID)

    apex.region("theIG").widget().interactiveGrid("getViews", "grid")

    you can then use the primary key column value to access the model as before (i think)

    EDIT : and please change you username to something more recognisable than "3052157"

    Gabriel Guzman
  • John like many others
    John like many others Member Posts: 110 Blue Ribbon
    edited Jun 26, 2020 9:10AM

    All your provided information were VERY helpful! All your assumptions where correct...

    For other having the same problem:

    - getActiveRecordId() delivers me only an ID if the record is in EDIT mode what I can't guarantee

    - The user CAN switch the order of the columsn (allowed)

    - Luckily getSelectedRecords([0]) provides the index (attribute 'index') in order to get the correct value in array of getColumns()

    I check (again) my name but couldn't find/change it in profile.

    Thanks a lot, very appreciated!

    KeyserGabriel Guzman