Preserve Checkbox state while Paginating in Interactive/Classic Report Oracle APEX

Share on:

Preserve Checkbox state while Paginating in Interactive/Classic Report Oracle APEX

Preview Someone has asked this question to me that how can we preserve checked checkboxes in session state.
This Problem will come when the user will check few checkboxes and go to next set of rows via pagination in the report when user will go back to the first set of pagination the original checked checkboxes will be no longer checked. this is because of the checked checkboxes are not preserved in the session state.

  • Create a collection for preserved the checked checkboxes in session state using the following code: Code Preview
 1DECLARE
 2BEGIN
 3IF APEX_COLLECTION.collection_exists(p_collection_name => 'CHECKBOX') THEN
 4apex_collection.delete_collection ('CHECKBOX');
 5END IF;
 6apex_collection.create_collection_from_query
 7                   (p_collection_name   => 'CHECKBOX',
 8                    p_query             => 'select ''N'' c001, EMPNO c001 from EMP',
 9                    p_generate_md5      => 'YES'
10                    );
11END;
  • Create an Interactive/classic Report using the following Query and Select set column attribute Escape special characters “No”. Report Query
 1select
 2    DISTINCT APEX_ITEM.CHECKBOX2(
 3        p_idx => 1,
 4        p_value => C002,
 5        p_attributes => decode(ac.c001, 'Y', 'CHECKED', 'UNCHECKED') 
 6                              || ' onclick = update_checkbox(''' 
 7                              || decode(ac.c001, 'Y', 'N', 'Y') 
 8                              || ''',''' 
 9                              || ac.seq_id 
10                              || ''',''' 
11                              || C002 
12                              || '''); ''' ) 
13    						  || apex_item.hidden(10, ac.seq_id) 
14   "SELECT",
15    EMPNO,
16    ENAME,
17    MGR,
18    JOB,
19    SAL
20FROM
21    EMP
22    inner join apex_collections ac on ac.collection_name = 'CHECKBOX'
23    and ac.C002 = EMPNO
24    ORDER BY EMPNO DESC
  • Create a function for getting values from checked checkbox while on click. Copy and Paste below Jquery Code as per screenshot. Define Jquery
 1function update_checkbox(p_val, p_seq, pPk_val) {
 2apex.server.process(
 3"CHECKBOX", { 
 4x01: p_val,
 5x02: p_seq,
 6x03: pPk_val
 7}, {
 8dataType: 'text',
 9success: function(pData) {
10console.log('---');
11}
12});
13}
  • Create an Ajax Call Back Process using the name “CHECKBOX” for save Checked Checkboxes value in collection: Define Jquery
 1BEGIN
 2    apex_collection.update_member (
 3        p_collection_name => 'CHECKBOX',
 4        p_seq => apex_application.g_x02,
 5        p_c001 => apex_application.g_x01,
 6        P_C002 => apex_application.g_x03
 7    );
 8exception
 9    when others then htp.p(dbms_utility.format_error_Backtrace || sqlerrm);
10end;

Demo

You might Like