Thursday, March 23, 2017

Oracle Apex Classic Report Refresh and keeping pagination

I have a project where I have a classic report(with multiple pages with 15 records in each page), I will need to refresh it each 3 seconds and also want to keep the pagination after each refresh.(mine is Apex 5)


Here is how I did it:

1. Create a page Item P_REGION_ID(hidden, default value set by following plsql:

DECLARE
   v_region_id VARCHAR2(4000);
BEGIN
    SELECT    region_id
         INTO v_region_id
         FROM apex_application_page_regions
        WHERE application_id = :APP_ID
          AND page_id         = :APP_PAGE_ID
          AND region_name     = 'Checking Database Request Status'; <-- you will need to replace the names with yours
   RETURN v_region_id;
END; 
2. Give a status ID to your region(in my example, I named mine DD)
3. put following in the page header (Function and Global Variables Section)
    var current_set;
    var first_record :=0;
    var last_record;
    var maxrec;
4. Create a dynamic action( After refresh and run following javascripts:)

current_set = $("#DD .t-Report-paginationText").html();
first_record = current_set.split(' ').filter(e => e !== "row(s)").filter(e => e !== "of").filter(e => e !== "-")[0];
last_record  = current_set.split(' ').filter(e => e !== "row(s)").filter(e => e !== "of").filter(e => e !== "-")[1];
var maxrec=last_record-first_record+1;

5. Put following in the page header(Execute when Page Loads):
if (first_record!=0) {
apex.widget.report.paginate('&P_REGION_ID.'{min:first_record,maxrec:max,fetched:0});
}


No comments:

Post a Comment