Interactive Grid (IG) disable warn on unsaved changes

How to Remove the Default Alert for Unsaved Changes in Oracle APEX Interactive Grids?


This article outlines a method to remove the default alert for unsaved changes in Oracle APEX Interactive Grids using JavaScript. This is useful in scenarios where the Interactive Grid shares the same save mechanism with another region, and unsaved changes prompts are not desired.

Tools and Technologies
To implement this solution, you need:

  • Oracle APEX
  • JavaScript

Use Case

Consider a situation where you have a page in Oracle APEX containing a form region and an Interactive Grid. When users update fields in the form region and attempt to refresh the Interactive Grid, they encounter a warning about unsaved changes. This can cause disruption, especially if both regions rely on the same save button, potentially leading to loss of selected values in the form.

Solution
To avoid unsaved changes alerts in this context, follow these steps:

Step 1: Assign a Static ID to the Interactive Grid

  • Open your Oracle APEX application in the Application Builder.
  • Navigate to the page containing your Interactive Grid.
  • Click on the Interactive Grid region and assign a unique Static ID. You will reference this ID in your JavaScript code.

Step 2: Create a Dynamic Action with JavaScript

  • In Oracle APEX, create a Dynamic Action that triggers on a change event, such as a button click.
  • Set the action type to “Execute JavaScript” and insert the following code:
var grid = apex.region('YOUR_STATIC_ID').widget().interactiveGrid('getViews').grid;
grid.model.clearChanges(); // Clears unsaved changes to avoid warnings
apex.region('YOUR_STATIC_ID').refresh(); // Refreshes the Interactive Grid


Replace ‘YOUR_STATIC_ID‘ with the Static ID of your Interactive Grid. This code achieves two key objectives:

  • It clears any unsaved changes in the Interactive Grid, preventing the default alert from appearing.
  • It refreshes the Interactive Grid, updating it with the latest data.


Important Considerations

  • Test Thoroughly: Ensure the new behavior works as expected and does not lead to accidental data loss or other unintended consequences.
  • Data Integrity: Consider alternative mechanisms to avoid losing data, such as implementing auto-save or providing clear save options.


Conclusion
By applying this solution, you can remove the unsaved changes alert from Oracle APEX Interactive Grids, ensuring that users can interact with the grid and other regions without interruptions from default alerts. This approach is particularly useful in scenarios where a form and an Interactive Grid share a save mechanism or need synchronized behavior.

Related Posts

Leave a Reply