In XAF applications, view settings are stored for each user individually. When a user changes a view (for example, adds a column to a list view or groups a detail view's items), these settings are saved in the user's model differences and applied to this view the next time this view is displayed.
The built-in View Variants Module allows you to create multiple predefined view settings in the Model Editor or in code. It also allows an end user to select a view variant at runtime.
This example implements functionality required to save customized view settings as new view variants at runtime, share them between users, and allow any user who has appropriate permissions to select a variant and apply its settings to a view.
NOTE: The approach demonstrated in this example may be inappropriate or overly complex in certain use cases. Thus, we cannot guarantee that it will work in all possible use case scenarios. Do not hesitate to modify it so it handles your business needs.
The example application uses a persistent class to store view settings in the database and a view controller with actions used to manage these settings (create, apply, and delete). Each user can create his/her own view variants. Each view variant can be optionally marked as shared, so that other users can see this variant in the UI and apply it to their views.
First, create the SettingsStore
business class used to store the View settings. This class should have the following properties:
-
Xml
- A string where serialized view settings are stored. -
Name
- The name of the view variant. -
OwnerId
- An identifier of the user who created this variant. -
IsShared
- Specifies whether this variant is shared with other users. -
ViewId
- An identifier of the view for which this variant is created.
Create a ViewController
that defines the following behavior:
-
The shared model settings are available to all users but cannot be edited by them.
-
Each user has his/her own default settings saved in the user's model and used when no variant is used.
-
The
SaveAsNewViewVariant
action creates a new view variant based on customizations made to a view. The created variant is assigned as the current variant. If this is the first variant created for the view, the action additionally creates a variant that stores the default settings (named "Default"). -
The
SelectViewVariant
action allows a user to select a view variant from a combo box and makes the selected variant current. This action is available when at least one variant exists. When a user changes the current view variant, all customizations previously made to the view are lost, except for changes made to the "Default" view variant. -
The
UpdateCurrentViewVariant
action saves customizations to the currently selected view variant. -
The
DeleteViewVariant
action deletes the current view variant. After deletion, the "Default" view variant becomes current and its settings are applied. -
The
UpdateDefaultViewVariant
action saves customizations made to the current view in the "Default" variant.
In the example application, the actions that ViewVariantsController
implements look as follows:
You can extend and adjust the demonstrated functionality based on your requirements. For example, you can:
-
Use the Security System facilities to prohibit certain users from deleting view variants.
-
Store the current variant in the model (see the Change the Application Model topic in our documentation) or in the user object's property and apply it when the corresponding view is opened.
(you will be redirected to DevExpress.com to submit your response)