Layout
- 2 minutes to read
ASPxCardView allows you to save information on its layout (filter and paging) to a database and then restore it. To specify what information on the ASPxCardView layout is saved, use options provided by the ASPxCardView.SettingsCookies property.
Automatic Layout Saving/Restoring
The ASPxCardView ASPxGridBase.ClientLayout event enables you to save the grid layout each time it is changed and restore it on first page load. This event provides the ASPxClientLayoutArgs.LayoutMode property, which specifies whether the grid layout should be saved or restored.
The following example shows how to save or restore the ASPxCardView layout to or from a data store.
protected void CardView_ClientLayout(object sender, ASPxClientLayoutArgs e)
{
if (e.LayoutMode == DevExpress.Web.ClientLayoutMode.Saving) {
SaveUserLayoutToDatabase(userID, "Account", e.LayoutData);
}
else {
if (System.IO.File.Exists(fileName))
e.LayoutData = RestoreUserLayoutFromDatabase(userID, "Account");
}
}
Manual Layout Saving/Restoring
ASPxCardView includes the following methods to manually save and restore its layout:
- ASPxGridBase.SaveClientLayout - returns a string that contains ASPxCardView layout data;
- ASPxGridBase.LoadClientLayout - restores the ASPxCardView layout from a specified string that contains its layout data.
The example below shows how to manually save and restore the previously saved layout. When the Save Layout or Load Layout button is clicked, the grid’s client ASPxClientCardView.PerformCallback method is used to send a callback to the server. This generates the server-side ASPxCardView.CustomCallback event, which is handled to save or restore the grid’s layout.
protected void ASPxCardView1_CustomCallback(object sender, ASPxCardViewCustomCallbackEventArgs e)
{
if (e.Parameters == "save") {
SaveUserLayoutToDatabase("userID", "Layout", ASPxCardView1.SaveClientLayout());
}
if (e.Parameters == "load") {
ASPxCardView1.LoadClientLayout(GetUserLayoutFromDatabase("userID", "Layout"));
}