The Interactive Grid (IG) in Oracle APEX provides a feature to select rows when edit mode is enabled. However, it comes with challenges such as:
Retrieving all selected records
Maintaining selected records between pagination pages
Preselecting specific records
Getting Selected Records
Starting from APEX 24.1, a new JavaScript API called selectionStateItem
allows setting an APEX page item with the selected values whenever the selection changes. More details are available in the APEX documentation.
Implementation
Add the following code to: IG > Attributes > Advanced > Initialization JavaScript Function
function (options) {
options.defaultGridViewOptions = {
selectionStateItem: "P100_SELECTED_IDS"
}
return options;
}
Result:
Persisting Selection Between Pages
By default, when pagination is set to "Page", selected records are lost when navigating between pages.
To retain selection, use the APEX JS API persistSelection
, which ensures records remain selected across pagination pages.
Implementation
Add the following code to: IG > Attributes > Advanced > Initialization JavaScript Function
function (options) {
options.defaultGridViewOptions = {
rowsPerPage: 5,
persistSelection: true
}
return options;
}
Result:
Preselect Records
If you need to retain selected records after a page refresh or preselect specific rows when the page loads, you can achieve this using JavaScript.
Implementation Add the following code to: Execute when Page Loads or a Dynamic Action on Page Load
var val = $v("P100_SAVED_IDS");
if (val) {
var array = val.split(":").filter(id => id.trim() !== ""); // Remove empty values
if (array.length > 0) {
apex.region('IG_DEMO').widget().interactiveGrid('setSelectedRecords', array);
}
}
This approach ensures that selected records persist, improving user experience when working with Interactive Grid selections in Oracle APEX.
Conclusion
By leveraging the selectionStateItem, persistSelection, and setSelectedRecords APIs in APEX Interactive Grid, you can efficiently manage row selection, ensuring a smoother user experience.