I want to add a customized button in oracle apex interactive grid to allow users to go back to the previous page. Can someone explain how I can do this in javascript? Thanks
2 Answers
Without javascript (recommended):
- Create your button, let's say BTN_PREVIOUS, and a hidden page item, P1_PREVIOUS_PAGE
- Create a new branch:
Point: After Porcessing
Behavior Type: Page Identified by Item (Show only)
Item: Select your hidden item created on step 1 (P1_PREVIOUS_PAGE)
Server-side Condition: When Button Pressed, BTN_PREVIOUS
Now for every page that calls this one, you have to set the item P1_PREVIOUS_PAGE with the number of the calling page. There's innumerable ways to to this (through declarative list entries, URL, javascript), I recommend you to read https://docs.oracle.com/cd/E59726_01/doc.50/e39147/concept_url.htm
Obs: if you do the steps above, make sure that every other process, computation and branches have a server side condition, because this method relies on submitting the page and you don't want your "Previous" button triggering any other logic that you have already created.
With javascript:
- Create your button, let's say BTN_PREVIOUS;
- Create a dynamic action
When: Event: Click
Selection Type: Button
Button: BTN_PREVIOUS
Inside the dynamic action create a true action:
Action: Execute JavaScript code
Code: history.back()
Although the javascript way is simpler, it's always preferable to use what the tool (APEX) has to offer.
window.document.location = document.referrer;
– Reza Saadati