The gReport.search function for APEX Interactive Reports

The gReport.searchfunction is used internally by Interactive Reports when a filter is applied on the report. Even if the gReport.search function is not documented by Oracle, taking a look at the source code for the Interactive Report Search Field gives us a clue about how the function is used internally:

<div>
  <input title=”Search Report” type=”text” size=”30″ maxlength=”4000″ value=”" id=”apexir_SEARCH” onkeydown=”if($f_Enter(event))
            {gReport.search(‘SEARCH’); return false;}”/>
<button
        type=”button”
        value=”Go”
        onclick=”gReport.search(‘SEARCH’)” >
  <span>Go</span>
</button>
</div>

The code above defines the Search Field input item and adds the search action for when the Enter key is pressed:

onkeydown="if($f_Enter(event))          {gReport.search('SEARCH'); return false;}

Similar code is used for the Go button:

onclick=”gReport.search(‘SEARCH’)”

The code snippets above reveals the fact that the gReport.search(‘SEARCH’) function is called to refresh and filter the Interactive Report on the fly, without refreshing the entire page.

Report filtering using gReport.Search

Using the gReport.search function described above, you can create custom filter mechanisms on Interactive Reports. For example, you can create an Interactive Report dynamic filtering mechanism based on a simple select list.

  1.  Create a Select List item in the same region as the existing Interactive Report.
  2.  Fill in the Label field with the value P15_FILTER.
  3. For the List of Values Query, paste in the following query and create the item:select distinct JOB display_value, JOB return_valuefrom EMP
  4. Open the created select list and go to the Element Section. Set the HTML Form Element Attributes to: onchange=”filterReport()”
  5. This will trigger the filterReport() JavaScript function each time the select list value is changed.
  6. Edit the page when the Interactive Report and select list are created, go to the JavaScript tab and add the filterReport() function code in the Function and Global Variable Declaration:

function filterReport()
{
   var selList = document.getElementById(‘P15_FILTER’);
   var IR = document.getElementById(‘apexir_SEARCH’);
   IR.value  = selList.value;
   gReport.search(‘SEARCH’);
}

When selecting a value from the select list containing the job titles, the selected value will be assigned to the Interactive Report’s search field and the report will be filtered dynamically on this value.

The code above simply gets the select list value (document.getElementById(‘P15_FILTER’).value) and assigns it to the apexir_SEARCH item, which is actually the report’s search field. Then, the gReport.search() function is called to filter the Interactive Report.

One thought on “The gReport.search function for APEX Interactive Reports

Leave a Reply