Skip to main content

Save and Restore Layout

  • 2 minutes to read

A pivot grid's layout contains settings which determine how its visual elements behave - their size, position within the control, etc. A layout can be saved and then applied to any other PivotGridControl. This allows you to customize a pivot grid just once, and then apply the saved settings to other pivot grids in other applications.

#Concepts

The DXPivotGrid provides multiple options, allowing you to specify which settings should be saved/restored. These options are described below:

Option Description
PivotSerializationOptions.AddNewFields Specifies whether the fields that currently exist in the pivot grid, but do not exist in a layout when it's restored, should be retained.
PivotSerializationOptions.AddNewGroups Specifies whether the field groups that currently exist in the pivot grid, but do not exist in a layout when it's restored, should be retained.
PivotSerializationOptions.RemoveOldFields Specifies whether fields that exist in a layout when it is restored, but don't currently exist in the pivot grid, should be discarded.
PivotSerializationOptions.StoreLayoutMode Gets or sets which settings should be saved when saving the PivotGrid's layout.

<dxpg:PivotGridControl Name="pivotGridControl1" dxpg:PivotSerializationOptions.RemoveOldFields="False"/>

To save the layout, use the PivotGridControl.SaveLayoutToStream or PivotGridControl.SaveLayoutToXml method. To restore the previously saved layout, use the PivotGridControl.RestoreLayoutFromStream or PivotGridControl.RestoreLayoutFromXml method respectively.

NOTE

The PivotGridControl.SaveLayoutToXml and PivotGridControl.RestoreLayoutFromXml methods directly access the file system, which is forbidden by the default Silverlight security sandbox. To use these methods, you should configure your application to require elevated trust. To learn how to do this, see the Trusted Applications MSDN topic.

Note that you should specify unique names for all pivot grid fields to correctly save and restore the layout. You can do this using the PivotGridField.Name property.

#Example: How to Save and Load the DXPivotGrid's Layout

The following example shows how to save the pivot grid's layout to a file in XML format. To investigate how this works, click the "Save" button, which calls the PivotGridControl.SaveLayoutToStream method. Once saved, the pivot grid's layout can then be restored by clicking the "Load" button, which calls the PivotGridControl.RestoreLayoutFromStream method.