Configure the Collapse And Expand View Events And Actions
You can use the Collapse and Expand view rule events and actions to control when views should expand or collapse, and what to do when a view expands or collapses. For example, you can use actions to populate a view with data on-demand; in other words, instead of loading a view with data when the form initializes, only load the data in the view if the person expands the view. This can help to improve form performance by delaying loading data until the person wants to see the data. You can use the Load and Initialize methods when the view is expanded instead of when the form initializes, to minimize the delay time when a form opens.
Collapse a view when the form opens
Data loads when the view is expanded
Try it yourself!
Expand/Collapse Rule Events
Use one of the following events in a rule, and select Collapse or Expand as the event to listen for:
When a View raises an event
When a subview executes a method
When a subform executes a method
Expand/Collapse Rule Actions
Use one of the following actions in a rule to expand or collapse a view:
Expand a View
Collapse a View
Expand a subview
Collapse a subview
Expand a View on a subform
Collapse a View on a subform
In this example, you have a form containing a Client Item view and Client List view. When you generate a form using multiple views, K2 automatically creates a default rule called When the Form is Initializing, which executes the Initialize method for all views when the form opens. The image below shows the default Initializing rule for this example.
Default rule configuration
If a view contains many records, such as the Client List view in this example, the Initialize action may cause a performance impact when the view loads because the form is locked until all views are loaded. To improve the user experience and speed up the load time of the form, you can move the then on Client List View, execute the Initialize method rule action to an Expand rule which only executes when the person expands the view. This allows you to execute the Initialize method of the Client List view when the view is expanded. You must also add an action to collapse the Client List view when the form loads. The images below show what the enhanced configuration looks like.
Enhanced rule configuration of the Initializing event containing the collapse method
Enhanced rule configuration showing the Expand event containing the Initialize method
Essentially, the rules are as follows:
- The form loads with the (Initializing) event.
- The Client Item view loads
- The Client List view collapses.
- When you click to expand the Client List view, the view loads.
Follow the steps below to configure the rule shown above.
- Edit the When the Form is Initializing rule, select then on Client List View, execute the Initialize method and click Remove or click the Remove icon as shown below.
- In the Actions tab, click the Collapse a View action in the Visibility section, and then select the Client List view as shown below.
Click OK to save the rule.
- Click Add Rule to add a rule when the Client List view is expanded.
- In the Events tab, click the When a View raises an event event in the View Method section, and then select the Client List as the view and Expand as the method as shown below.
- Add the Initialize method that you removed from the default form Initialize rule. Go to the Actions tab, click the Execute a View method action in the SmartObject Interaction section, and then select the Client List as the view and Initialize as the method as shown below. Click OK to save the rule. The Client List view now opens when the view is expanded instead of when the form opens.
- Save and finish the view, and then run the form to test that the view load-when-expanded behavior works as expected.