Manage Dashboard State
- 8 min to read
A dashboard state describes the result of client actions end-users perform on a dashboard:
selected master filters values
current drill-down levels
a selected tab page
Range Filter settings
a selected dashboard item layer1
selected parameter values
The Web Dashboard allows you to manage a dashboard state in the following ways:
- API Overview
- Include a Dashboard State to URL
- Apply a Dashboard State during Server-Side Export
- Example 1: Specify a Default Dashboard State
- Example 2: Save a Dashboard State to Cookies
The DashboardState class represents a dashboard's state on the server side and includes states of individual dashboard items (the DashboardState.Items property) and currently selected parameter values (DashboardState.Parameters). On a client side, a dashboard state is a JSON object that stores the same data. The table below lists main server-side and client-side API members related to obtaining and setting a dashboard state.
To initialize the DashboardState object using a JSON object obtained from a client side, use the DashboardStateExtensions.LoadFromJson extension method. Use DashboardStateExtensions.SaveToJson to save the current DashboardState to JSON.
Include a Dashboard State to URL
You can supply end-users with the capability to share a dashboard state by appending it to the URL of the currently browsed dashboard. To do this, enable the DashboardExtensionSettings.IncludeDashboardStateToUrl property.
In this case, the resulting link allows end-users to open the dashboard with the specified state. Note that these properties are in effect when the DashboardExtensionSettings.WorkingMode is set to WorkingMode.Viewer or WorkingMode.ViewerOnly.
You can also include the identifier of the selected dashboard to URL using the DashboardExtensionSettings.IncludeDashboardIdToUrl property.
Apply a Dashboard State during Server-Side Export
You can apply a specified dashboard state when performing server-side exporting using methods exposed by the ASPxDashboardExporter class, for instance:
- WebDashboardExporter.ExportToPdf / WebDashboardExporter.ExportDashboardItemToPdf
- WebDashboardExporter.ExportToImage / WebDashboardExporter.ExportDashboardItemToImage
- WebDashboardExporter.ExportToExcel / WebDashboardExporter.ExportDashboardItemToExcel
To learn more, see Manage Exporting Capabilities.
Example 1: Specify a Default Dashboard State
The sample illustrates how to specify a dashboard state (such as master filter or parameter values) in code and how to apply this state when loading a dashboard for the first time. In this example, the DashboardState object holds the required dashboard state. The DashboardConfigurator.SetDashboardStateService method is used to apply the specified dashboard state when loading a dashboard.
A complete sample project is available at https://github.com/DevExpress-Examples/aspnet-mvc-dashboard-how-to-specify-a-default-dashboard-state-in-code-t586607.
- Index.cshtml (VB.NET)
- Index.cshtml (C#)
Imports System.Web.Mvc Namespace MvcDashboard_DefaultDashboardState.Controllers Public Class HomeController Inherits Controller Public Function Index() As ActionResult Return View() End Function End Class End Namespace
Example 2: Save a Dashboard State to Cookies
The sample illustrates how to save the current ASP.NET MVC Dashboard state (such as master filter or parameter values) to cookies on the client side and restore this state on the server side. The following API is used in this example:
- The ASPxClientDashboard.DashboardStateChanged event is handled to obtain the current dashboard state.
- The ASPxClientUtils.SetCookie client-side method is used to save the dashboard state to cookies.
- The DashboardConfigurator.SetDashboardStateService method is used to apply the dashboard state loaded from the cookies.
A complete sample project is available at https://github.com/DevExpress-Examples/aspnet-mvc-dashboard-how-to-save-a-dashboard-state-to-cookies-t589151.
- Index.cshtml (C#)
- Index.cshtml (VB.NET)
Imports System.Web.Mvc Namespace MvcDashboard_DashboardStateCookies.Controllers Public Class HomeController Inherits Controller Public Function Index() As ActionResult Return View() End Function End Class End Namespace