Hi Experts,
I am working with an Interactive Grid (IG) in Oracle APEX (static ID = router_ig).
The IG has APEX$ROW_SELECTOR enabled, and the primary key column is ID.
My Requirement
a. Users can select multiple rows in the IG.
b. The selected row IDs should be stored in a page item P3_DUMMY (colon-separated values like 1:4:5).
c. The IG should auto-refresh every 5 seconds so that updates in the underlying table are reflected.
d. After refresh, the previously selected rows should remain selected in the IG (checkboxes should stay checked).
What I Did
Store selections in P3_DUMMY:
a. I used a DA on Selection Change [Interactive Grid]:
var model = this.data.model,
ids = [],
last;
for (var i = 0; i < this.data.selectedRecords.length; i++) {
last = model.getValue(this.data.selectedRecords[i], "ID");
ids.push(last);
}
apex.item("P3_DUMMY").setValue(ids.join(":"));
b. Auto-refresh the IG every 5s:
On Page Load:
setInterval(function(){
apex.region("router_ig").refresh();
}, 5000);
c. Restore selections after refresh:
DA on Custom Event → interactivegridrefresh:
(function(){
var grid = apex.region("router_ig").widget().interactiveGrid("getViews","grid");
var model = grid.model;
var selIds = apex.item("P3_DUMMY").getValue();
if(!selIds) return;
var idsArray = selIds.split(":");
var recordsToSelect = [];
model.forEach(function(record){
var recId = model.getValue(record, "ID");
if(idsArray.indexOf(recId.toString()) !== -1){
recordsToSelect.push(record);
}
});
grid.setSelectedRecords(recordsToSelect);
})();
The Problem
a. The IG does refresh every 5 seconds, but the selected rows are not being restored.
b. I suspect I may be using the wrong event (interactivegridrefresh), or that I need to hook into a different IG lifecycle event such as interactivegridviewchange.
My Question
a. What is the correct way to retain Interactive Grid row selections after auto-refresh in APEX?
b. Which event (interactivegridrefresh, interactivegridviewchange, or something else) should I use so that the selections are reliably restored?
c. Are there best practices for handling auto-refresh + row selection retention in IG?
Thanks in advance for your help 🙏