Use jQuery to check if a report returned rows in Apex
In order to conditionally hide/show a button, I needed to know whether a particular report on a page returned any rows.
This can easily be done with a line of jQuery, which differs between classic and interactive reports:
- Make sure to give your report a static ID. In this example it is emp.
- Classic Report: If data is returned there will be a div with an id that prepends ‘report_’ to the report static id. Check the length of that div to find out if it exists. If it doesn’t, the length will be zero, meaning no rows were returned.
-
$('#report_emp').length
-
- Interactive Report:
-
$('#emp').find('div[id="apexir_DATA_PANEL"] table').length
- Here, if the length comes back as one, the report returned no rows.
-
Thanks to @rimblas for a correction.