πŸ” Return to the Same Page and Row in an Interactive Grid After Navigating Back in Oracle APEX

πŸ” Return to the Same Page and Row in an Interactive Grid After Navigating Back in Oracle APEX

1. Overview

This post explains how to automatically return to the same row and page in an Interactive Grid (IG) after navigating away and coming back to the report. The solution ensures that the user’s position and selected record remain intact, enhancing the overall user experience.

This functionality is achieved using JavaScript and Oracle APEX page items.

2. Technologies and Tools Used

To implement this feature, the following tools and technologies are used:

  • Oracle APEX
  • JavaScript

3. Use Case

In many Oracle APEX applications, users navigate between different pages β€” for example, opening a detail page from a report and then returning to the report.

Without additional handling, the Interactive Grid resets to the first page, and the user loses their previously selected row or position.

This approach:

  • Allows users to return to theΒ exact same row and paginationΒ after coming back.
  • Saves timeΒ by avoiding the need to manually search for the same record again.
  • Provides aΒ seamless navigation experienceΒ across pages.

4. Implementation Steps

Follow the steps below to achieve this functionality:

Step 1: Create four hidden page items on the Interactive Grid report page. These items will store the current page number, selected row primary key, and other necessary details.

Step 2: Create a Dynamic Action on the Interactive Grid to store the selected row’s details into the hidden page items using JavaScript.

Action: Execute JavaScript

Code:
var gridID = β€œEMPLOYEES_IR”;

var ig$ = apex.region(gridID).widget();

var grid = ig$.interactiveGrid(β€œgetViews”,”grid”);

var selectedRecord = grid.getSelectedRecords();

var gridData = apex.region(β€œEMPLOYEES_IR”).call(β€œgetViews”).grid.view$.data(β€œapex-grid”);

var currentPage = Math.floor(gridData.pageOffset / gridData.pageSize) + 1;

apex.item(β€˜P4_PAGE_ID’).setValue(currentPage);

var i,I_SELECTED_VAL,

model = this.data.model;

for ( i = 0; i < this.data.selectedRecords.length; i++ ) {

I_SELECTED_VAL = model.getValue( this.data.selectedRecords[i], β€œEMPNO”);

}

apex.item(β€œP4_PRI_VALUE”).setValue (I_SELECTED_VAL);

Step 3: Create another Dynamic Action on Page Load to automatically highlight and navigate to the stored row when the user returns.

Code:

setTimeout(function() {

var val = $v(β€œP4_PRI_VALUE_1”);

apex.region(β€œEMPLOYEES_IR”).call(β€œgetViews”).grid.view$.grid(β€˜gotoPage’,$(β€˜#P4_PAGE_ID_1’).val()-1);

apex.region(β€˜EMPLOYEES_IR’).widget().interactiveGrid(β€˜setSelectedRecords’, [String(val)]);

}, 1000);

Step 4: On the detail page (or target page), create two hidden page items (e.g., P1_PAGE_ID and P1_PRI_VALUE) to receive the values passed from the previous report page.

Step 5: Configure the Back button on the detail page to pass these stored values back to the report page, as shown in the reference screenshot.

Step 6: On the report page, create a branch to handle the incoming values and restore the user’s previous position and selected row.

5. Output 

After implementing the above steps, when a user navigates back from another page, the Interactive Grid will automatically:

  • Open the sameΒ pagination page.
  • Highlight theΒ previously selected row.

This ensures a smooth and consistent user experience in Oracle APEX applications

Thanks for reading! We hope this guide helped you implement Prevent Duplicate Tabs to open in Oracle APEX Using JavaScript.

Love coding? Me too! Let’s keep in touch – subscribe to my website for regular chats on Oracle APEX, PL/SQL,SQL JavaScript, and CSS.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *