Today, I came across a post on the APEX discussion forum where Karoly Dede raised a request to restrict row selection in an Interactive Grid. In this post, we’ll share the solution to his request.
In Oracle APEX, the Interactive Grid (IG) is a powerful component that allows users to view, edit, and interact with data dynamically. However, in certain business scenarios, developers may need to restrict how many rows a user can select at a time — for example, when performing bulk updates, approvals, or exports.
In this example, we use a Dynamic Action on the “Selection Change [Interactive Grid]” event to:
-
Detect how many rows the user has currently selected.
-
Display an error message if the count exceeds five.
-
Automatically deselect the extra rows to enforce the limit.
This approach ensures that validation happens instantly on the client side, without requiring a page submit or PL/SQL process — making the user experience smooth and responsive.
Paste the following JS code on selection change Dynamic action.
var grid = apex.region("EMP").widget(); // static ID of the IG region
var view = grid.interactiveGrid("getViews", "grid");
var model = view.model;
var selectedRecords = view.getSelectedRecords();
var count = selectedRecords.length;
if (count > 5) {
apex.message.clearErrors();
apex.message.showErrors([
{
type: "error",
location: "page",
message: "You cannot select more than 5 records.",
unsafe: false
}
]);
view.setSelectedRecords(selectedRecords.slice(0, 5));
}
Comments
Post a Comment