I've written collapsible list in PL/SQL dynamic content using HTML and JavaScript.
Is there any way to insert ID of clicked item into table? Clickable fields are buttons.
Thanks
edit
for i in c loop
HTP.P('<button type="button" >
'i.Header of list'
('</button><div ><p>'i.content of list'</p></div>'));
end loop;
CodePudding user response:
Here is an example based on the EMP/DEPT sample dataset.
Step 1: Create pl/sql dynamic content region. Make sure the button has a (1) a custom class to capture the click event and (2) a data attribute to uniquely define the row.
for i in (SELECT * FROM emp) loop
htp.p(apex_string.format('</button><div data-empno="%0"><p>%1</p></div>',i.empno,i.ename));
end loop;
Step 2: create a (hidden) page item to hold the identifier of the row you clicked, in my case P104_EMPNO.
Step 3: Create a dynamic action to set the value to P104_EMPNO to the value empno of the row button you clicked in the report.
- Selection Type: JQuery Selector
- JQuery Selector: .my-button-js
True Action 1:
- Action: "Set Value"
- Set Type: "Javascript Expression"
- Javascript Expression:
this.triggeringElement.dataset['empno']
- Affected Element: P104_EMPNO
True Action 2:
- Action: "Execute Javascript Code", Code:
$.event.trigger("mybuttonclicked");
Step 4: Create a dynamic action to fire on the custom event you fired in True Action 2 of Step 3.
- Event: Custom
- Custom Event: mybuttonclicked
- Selection Type: "Javascript Expression"
- Javascript Expression:
document
True Action 1:
- Action: Execute Server-side Code
- Language: PL/SQL
- Code:
UPDATE EMP SET sal = sal * 1.1 WHERE empno = :P104_EMPNO;
- Items to Submit: P104_EMPNO