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

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
DECLARE
BEGIN
IF APEX_COLLECTION.collection_exists(p_collection_name => 'CHECKBOX') THEN
apex_collection.delete_collection ('CHECKBOX');
END IF;
apex_collection.create_collection_from_query
                   (p_collection_name   => 'CHECKBOX',
                    p_query             => 'select ''N'' c001, EMPNO c001 from EMP',
                    p_generate_md5      => 'YES'
                    );
END;
  • Create an Interactive/classic Report using the following Query and Select set column attribute Escape special characters “No”. Report Query
select
    DISTINCT APEX_ITEM.CHECKBOX2(
        p_idx => 1,
        p_value => C002,
        p_attributes => decode(ac.c001, 'Y', 'CHECKED', 'UNCHECKED') 
                              || ' onclick = update_checkbox(''' 
                              || decode(ac.c001, 'Y', 'N', 'Y') 
                              || ''',''' 
                              || ac.seq_id 
                              || ''',''' 
                              || C002 
                              || '''); ''' ) 
    						  || apex_item.hidden(10, ac.seq_id) 
   "SELECT",
    EMPNO,
    ENAME,
    MGR,
    JOB,
    SAL
FROM
    EMP
    inner join apex_collections ac on ac.collection_name = 'CHECKBOX'
    and ac.C002 = EMPNO
    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
function update_checkbox(p_val, p_seq, pPk_val) {
apex.server.process(
"CHECKBOX", { 
x01: p_val,
x02: p_seq,
x03: pPk_val
}, {
dataType: 'text',
success: function(pData) {
console.log('---');
}
});
}
  • Create an Ajax Call Back Process using the name “CHECKBOX” for save Checked Checkboxes value in collection: Define Jquery
BEGIN
    apex_collection.update_member (
        p_collection_name => 'CHECKBOX',
        p_seq => apex_application.g_x02,
        p_c001 => apex_application.g_x01,
        P_C002 => apex_application.g_x03
    );
exception
    when others then htp.p(dbms_utility.format_error_Backtrace || sqlerrm);
end;

Demo

You might Like


comments powered by Disqus