Tuesday, March 11, 2014

Expand or collapse a report group depending on the value of a parameter

Problem: synchronize expand/collapse depending on the value of a parameter

In a report with a tablix with different group levels, the lower levels need to be expanded automatically when a specific parameter is filled in and stay collapsed when the parameter has not been filled in. This report has subscriptions that are emailed in HTML format to general managers who do not need to see all detail. The same report has subscriptions for regional managers who only need to see their region with the detail for child groups expanded automatically. when the Report is opened with IE the proper expand/collapse symbols must be shown.

Solution: use expressions to set value for Hidden and for InitialToggleState

The parameter is called RegionId, when the parameter value is null then only country and region is shown, the other groups are collapsed.

E.g. on the rowgroup ZoneName.

Set Hidden property

Select group properties

image

In the dialog window select Visibility in the left pane and click Show or hide based on an expression.

image

The display can be toggled by the parent group report item ‘RegionName’.

Click on the Fx button to create the expression

image

=IsNothing(Parameters!RegionId.Value)

This expression is to set the value of the Hidden property: when Nothing is filled in for the regionId then the isNothing function evaluates to True, meaning that the ZoneGrup will be hidden (collapsed).


To the contrary, the RegionName and CountryName group visiblity is set to ‘Show’.


Set the InitialToggleState value

This has to be set to True when the Region is not selected to show (+) sign. Set to False when the Region is selected to show a (-) sign.


Select the ZoneName textbox, in the Visual Studio properties window, scroll down to the InitialToggleState property


Set the property to the expression:



=Not(IsNothing(Parameters!RegionId.Value))

image


The same has to be done for the RegionName and CountryName textboxes.


Result


Initial report when no Region is selected:



  • Country group is expanded and (-) is shown to collapse it.

  • Region group is collapsed and (+) is shown to expand.

image


The initial report when the Region id is set to a specific value (as would be the case for a subscription for the particular region manager).



  • Country group is expanded and (-) is shown to collapse it.

  • Region group is expanded and (-) is shown to collapse it.

  • Zone is expanded and (-) is shown to collapse it.

image

No comments: