Skip to content

Save customized view settings at runtime and share them between users.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/xaf-save-and-share-custom-view-settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XAF - How to Save and Share Custom View Settings

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.

Implementation Details

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.

Add a Persistent Class to Store View Settings

First, create the SettingsStore business class used to store the View settings. This class should have the following properties:

  1. Xml - A string where serialized view settings are stored.

  2. Name - The name of the view variant.

  3. OwnerId - An identifier of the user who created this variant.

  4. IsShared - Specifies whether this variant is shared with other users.

  5. ViewId - An identifier of the view for which this variant is created.

Add a Custom View Controller

Create a ViewController that defines the following behavior:

  1. The shared model settings are available to all users but cannot be edited by them.

  2. Each user has his/her own default settings saved in the user's model and used when no variant is used.

  3. 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").

  4. 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.

  5. The UpdateCurrentViewVariant action saves customizations to the currently selected view variant.

  6. The DeleteViewVariant action deletes the current view variant. After deletion, the "Default" view variant becomes current and its settings are applied.

  7. 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:

View Controller Actions in UI

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.

Files to Review

Documentation