dashboard-devexpress-dot-dashboardaspnetcore-dot-dashboardbuilder-dot-initialdashboardstate-x28-system-dot-string-x29.md
Specifies the initial state of the loaded dashboard.
Namespace : DevExpress.DashboardAspNetCore
Assembly : DevExpress.Dashboard.v25.2.AspNetCore.dll
NuGet Package : DevExpress.AspNetCore.Dashboard
public DashboardBuilder InitialDashboardState(
string initialDashboardState
)
Public Function InitialDashboardState(
initialDashboardState As String
) As DashboardBuilder
| Name | Type | Description |
|---|---|---|
| initialDashboardState | String |
A string that defines the initial dashboard state.
|
| Type | Description |
|---|---|
| DashboardBuilder |
A reference to this instance after the operation has completed.
|
Use the InitialDashboardState method to set the identifier of the dashboard to which the state is applied.
To specify the initial dashboard state, initialize the DashboardState object on a server, save this object to JSON using the SaveToJson(DashboardState) method, and assign the resulting string to InitialDashboardState.
The sample illustrates how to specify a dashboard state (such as a 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 defined in the Controller stores the dashboard state. The MVC approach is used to pass the specified dashboard state to the View’s DashboardBuilder.InitialDashboardState property and use this state when loading a dashboard.
@model DevExpress.DashboardCommon.DashboardState
<div style="position: absolute; left:0;top:0;right:0;bottom:0;">
@(Html.DevExpress().Dashboard("clientDashboardDesigner1")
.ControllerName("DefaultDashboard")
.Width("100%")
.Height("100%")
.WorkingMode(WorkingMode.Viewer)
.InitialDashboardState(Model.SaveToJson())
.Extensions(extension => extension.UrlState(state => state.IncludeDashboardStateToUrl(true)))
)
</div>
using AspNetCoreDashboardState.Models;
using DevExpress.DashboardCommon;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace AspNetCoreDashboardState.Controllers {
public class HomeController : Controller
{
public IActionResult Index() {
DashboardState dashboardState = new DashboardState();
DashboardParameterState parameterState =
new DashboardParameterState("countryParameter", "USA", typeof(string));
DashboardItemState gridFilterState = new DashboardItemState("gridDashboardItem1");
gridFilterState.MasterFilterValues.AddRange(new List<object[]>() {
new string[1] { "Andrew Fuller" },
new string[1] { "Laura Callahan" }
});
DashboardItemState treemapDrilldownState = new DashboardItemState("treemapDashboardItem1");
treemapDrilldownState.DrillDownValues.Add("Beverages");
DashboardItemState rangeFilterState = new DashboardItemState("rangeFilterDashboardItem1");
rangeFilterState.RangeFilterState.Selection =
new RangeFilterSelection(new DateTime(2015, 1, 1), new DateTime(2016, 1, 1));
dashboardState.Parameters.Add(parameterState);
dashboardState.Items.AddRange(new List<DashboardItemState>() {
gridFilterState,
treemapDrilldownState,
rangeFilterState }
);
return View(dashboardState);
}
public IActionResult Error() {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
@using DevExpress.DashboardWeb
@using DevExpress.AspNetCore
@using DevExpress.DashboardAspNetCore
@using AspNetCoreDashboardState
@using AspNetCoreDashboardState.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
See Also