IG의 각 Row에 버튼을 생성하기 위해 SQL에서 HTML을 작성하였으나 일부 작동에 두 가지 문제가 발생.
SQL :
case APR_YN
when 'Y' then '<span style="text-align=center">Completed</span>'
else '<button onclick="javascript:alert(123)" class="t-Button t-Button--default t-Button--hot t-Button--stretch">Proc Required</button>'
end APR_YN
- 버튼은 잘 생성되었고 alert 메세지도 작동을 하였으나 그 이후 자동적으로 페이지가 Refresh 되는 현상이 있고,
- 버튼을 눌렀을 때 PL/SQL 로 프로세싱이 필요한 상황에 Dynamic Action/Process를 제어할 수가 없었음. (예를 들어 각 Row는 주문 정보라고 하면 관리자는 주문 내용을 확인하고 필요에 따라 일부를 수정할 수 있고, 체크가 끝나면 주문하는 프로세스를 버튼을 클릭하여 진행)
APEX 전문가 Comment :
I recommend to not generate HTML in SQL. Use an HTML Expression column instead. Use substitutions to put any needed context such as a primary key into the button markup as data- attributes. Use the button builder from the UT sample app to make a nice looking button. Give the button a distinct class (in addition to all the style classes) such as js-do-that-thing.
I recommend to not use javascript: pseudo scheme URLs.
Next create a delegated click handler on the IG region. This is a DA with event click and dynamic scope. Give the IG region a static id such as ‘myIG’. Set the DA selection type to jQuery Selector and for the selector use the button class ‘.do-that-thing’. Then set event scope to dynamic and in the static container enter a selector for the reiong '#myIG'.
Then you can use an Execute PL/SQL Code action. You can first use a JavaScript action to extract any context info from the button data- attributes and put it in page items to be sent in the PL/SQL action.
요약하면,
- SQL 에서 HTML 생성하지 말고 컬럼을 가져와 Type을 HTML Expression 사용
- 버튼에 Primary Key 같은 값을 셋팅, Class 할당하여 활용
- IG 리전에서 static id 를 지정하여 DA Click Event >> jQuery Selector >> Execute PL/SQL
20210323.