Skip to main content

Oracle APEX Tip: Restrict Row Selection in Interactive Grid Using JavaScript

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));

}


Demo_Application


Comments

Popular posts from this blog

Reusable JS Functions for Field Validation in Oracle APEX Forms

 These reusable JavaScript functions provide client-side validation for Oracle APEX forms, improving data accuracy before submission. They allow developers to enforce mandatory fields and ensure certain fields contain only numeric values . By using these functions, APEX forms become more user-friendly and robust , reducing the chance of invalid data entry. Step 1: Create a Static Content region on the Global Page using the Blank with Attributes template. Step 2: Paste the following code into the HTML Source section of the region. <script>     function validateInputField(inputFieldId, pageItemName, errorMessage) {         $(inputFieldId).focusout(function() {             var itemValue = apex.item(pageItemName).getValue();             apex.message.clearErrors(pageItemName);             if (!itemValue) {               ...

Reusable JavaScript Function to Highlight Holidays on APEX Date Picker Item

Date pickers are an essential part of web applications, especially when users need to select dates for bookings, reports, or scheduling tasks. However, in many business scenarios, certain dates like holidays, weekends, or special events need to be visually distinguished to prevent users from selecting them by mistake. In this blog, we will create a reusable JavaScript function that highlights holiday dates in an Oracle APEX date picker. This approach allows developers to call the function anywhere in their application, ensuring consistency and reducing redundant code. By the end, you’ll have a flexible solution to visually mark holidays on any date picker item in your APEX applications. Step 1: Create a Static Content region and set it to Blank with Content under the region attributes. Step 2: Inside that region, enclose a <script> tag and paste the following JavaScript function. function applyHolidayFormatterToDateItems(itemNames) {   const holidayList = [   ...

Adding Custom Buttons to Oracle APEX Date Picker Footer (Set Start and End of Month)

In Oracle APEX, the built-in Date Picker is simple and functional — but sometimes, users need quick shortcuts for commonly used dates. For example, setting the first or last day of the current month with just one click can save time and reduce input errors. In this post, we’ll enhance the Oracle APEX Date Picker by adding two custom buttons — “Set Month Start” and “Set Month End” — directly inside the date picker footer. Using a small piece of jQuery code, you can seamlessly integrate these buttons without modifying the native APEX components. By the end of this guide, your Date Picker will not only look smarter but also provide a faster and more user-friendly experience.  ⚙️ This customization is created for learning purposes. Paste the below code on execute when page loads (js) apex.jQuery(document).on('focus', '#P20_START_DATE', function() {   var intervalId = setInterval(function() {     var $footer = apex.jQuery('.a-DatePicker-footer');     if ($f...