String customizations = dataSource.SaveCustomizations();
This topic explains how to save and load the user customizations made to the way the data is presented in the xamPivotGrid™ control.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
In xamPivotGrid, users can customize the View presenting the data slide in the following aspects:
Selected database
Selected cube
Selected measure group
Current hierarchies used in rows, columns, filters
Current measures
Location of the measure list view model (if applicable)
Expansion states of filter members
Selection states of filter members
Expansion states of members (for rows and columns)
Currently applied sort orders (for both values and member names within a level)
Applied Excel®-style filters (Advanced filters)
Deferred layout update state
The information about these customization aspects is stored in the data source controls ( FlatDataSource™ and XmlaDataSource™) used by the xamPivotGrid control and and in the OlapXAxis™ component of the xamDataChart™ control and can be saved and consequently loaded.
In order to save the current view of xamPivotGrid , you need to save the current values of the properties that define that view. All relevant information is available in the data source instance set as the value of the DataSource property of the xamPivotGrid . The DataSourceBase class (from which all other multi-dimensional (OLAP) data sources inherit) exposes extension methods for saving and loading the current state of the data source. The customizations can be written to either a string or in a stream.
The actual saving is done by the SaveCustomizations method. There are two overloads for this method. One returns a string containing the saved customizations, and the other expects a stream into which the customizations are written. You invoke one of them depending on your preferences.
The LoadCustomizations methods load previously [_Saving_customizations]saved customizations. Saved customizations can be loaded from a string or stream. In addition to this, in both cases, an Action can be specified to be executed when the load has completed. Therefore there are four overloads of the LoadCustomizations
method, one for each parameter combination.
In practice, the implementation of the loading usually goes together with configuring of some post-load action. For example, because the process of loading the customizations may take some time, you may want to execute some custom code when it is finished, or be notified for its completion. To do this, call one of the LoadCustomizations
overloads that accept an action parameter. When the load process finishes, the action is executed. The action accepts a string parameter which will contain descriptions of the errors that occurred during the load process if such errors have occurred.
Following are the general requirements for saving and loading customizations:
Data requirements
In order for a set of customizations to load, the source and destination data sources must have the same database (metadata) structure. Otherwise the load process will either fail or be incomplete.
References
Defining the SaveCustomizations and LoadCustomizations extension methods for the DataSourceBase
class in the Infragistics.Olap
namespace
using
/Imports
directive to the Infragistics.Olap
namespace
The following table maps the configurable aspects that are saved by the SaveCustomizations methods to the values of the respective properties and the data source type to which they apply.
The following procedure demonstrates the process of saving the customizations for a data source. To save the user customizations, one of the SaveCustomizations methods is called. The example Code assumes that a variable of type DataSourceBase (or a class inherited from it) named dataSource
holds a reference to a data source object.
In C#:
String customizations = dataSource.SaveCustomizations();
In Visual Basic:
Dim customizations = dataSource.SaveCustomizations()
In C#:
using (Stream stream = [initialize the stream here])
{
dataSource.SaveCustomizations(stream);
}
In Visual Basic:
Using stream As [initialize the stream here]
dataSource.SaveCustomizations(stream)
End Using
The following procedure loads a previously saved customization of a multi-dimensional (OLAP) data source.
The procedure contains an optional step of configuring a post-load action which, in this case, is displaying load errors in a message box. To that purpose, a sample method (LoadCompletedAction
) is defined.
To complete the procedure, you need the following:
A variable of type DataSourceBase (or a class inherited from it) named dataSource
holding a reference to a data source object
Following is a conceptual overview of the process:
1. (Optional) Defining a post-load action
2. Calling the LoadCustomizations
method
The following demonstrate how to load a customization.
(Optional) Define a post-load action.
The following code snippet defines a sample method which displays the load errors in a message box:
In C#:
public void LoadCompletedAction(string loadErrors)
{
if(!string.IsNullOrWhiteSpace(loadErrors))
{
MessageBox.Show(loadErrors);
}
}
In Visual Basic:
Public Sub LoadCompletedAction(loadErrors As String)
If Not String.IsNullOrWhiteSpace(loadErrors) Then
MessageBox.Show(loadErrors)
End If
End Sub
Call the LoadCustomizations method.
To load customizations that have been earlier saved to a string or a stream, call one of the LoadCustomization
methods passing the String
or Stream
argument.
The following code snippet demonstrates how to load a customization from a string when passing an action argument.
In C#:
dataSource.LoadCustomizations(customizations, LoadCompletedAction);
// or
using(Stream customizations = [initialize stream here])
{
dataSource.LoadCustomizations(customizations, LoadCompletedAction);
}
In Visual Basic:
dataSource.LoadCustomizations(customizations, LoadCompletedAction)
‘ or
Using stream As [initialize the stream here]
dataSource.LoadCustomizations(customizations, LoadCompletedAction)
End Using
If you prefer not to specify the action parameter (LoadCompletedAction
), use the overloads of the LoadCustomizations
methods that accept only one argument.