Monday, 17 September 2018

Hide region if no data found

I have a diagnostic page where I hide classic report regions that aren't relevant - ie, have no data returned.

Here I create a dynamic action that executes After Refresh of the relevant region.

Dynamic Action definition

The client-side condition evaluates the presence of the .nodatafound class within a classic report, which is present only when no records are returned.

Inspect element of region with no records

The dynamic action then shows/hides the region, depending on the result of the JavaScript expression:
$(this.triggeringElement).find('.nodatafound').length == 1

The triggering element is the region, so find the class within that region, count the result set, and compare to value 1.


Instead of the region itself, this could relate to other components only relevant when records are returned.

As Maxime pointed out in the comments, here I was focussing on classic report regions. The relevant classes you may be looking for include:

  • Classic Report (versatile): nodatafound
  • Interactive Report (IR): a-IRR-noDataMsg
  • Interactive Grid (IG): a-GV-noDataMsg

This can mean there is no need for a server-side condition to test for existence.

With this dynamic action, the region could re-appear upon refresh with results, making the page more interactive without requiring full page submission.

3 comments:

Maxime Tremblay said...

Hello Scott

Might also want to consider the classes for the IR and the IG.
IR: a-IRR-noDataMsg
IG: a-GV-noDataMsg

Regards
Max

karthik said...

Hello Scott

Please share us details for, how to hide the charts when no data found

Scott Wesley said...

I thought I had seen this somewhere, but couldn't find an example.

Turns out this expression works, but relies on the text inside the no data found attribute, in my case 'no records'. This attribute doesn't accept HTML, replace shortcuts, or listen to the &P1_ITEM!RAW. substitution.
$('text:contains(records)').length == 1