Search results

State maintenance in ASP.NET Core Dashboard Layout control

The current layout structure of the Dashboard Layout component can be obtained and saved to construct another dashboard with same panel structure using the serialize public method of the component. This method returns the component’s current panel setting which can be used to construct a dashboard with the same layout settings.

The following sample demonstrates how to save and restore the state of the panels using the serialize method. Click Save to store the panel’s settings and click Restore to restore the previously saved panel settings.

@model WebApplication.Controllers.HomeController.spacingModel

    <!--  Button element declaration -->
    <ejs-button id="save" cssClass="e-primary" content="Save"></ejs-button>
    <ejs-button id="restore" cssClass="e-flat e-outline" content="Restore"></ejs-button>
    <!-- end of button element -->
<div style="padding-top: 15px;">
    <!--  DashboardLayout element declaration -->
    <ejs-dashboardlayout id="dashboard_default" columns="5" created="onCreated" cellSpacing="@Model.cellSpacing">
            <e-dashboardlayout-panel sizeX="1" sizeY="1" row="0" col="0" content="<div class='content'>0</div>">
            <e-dashboardlayout-panel sizeX="3" sizeY="2" row="0" col="1" content="<div class='content'>1</div>">
            <e-dashboardlayout-panel sizeX="1" sizeY="3" row="0" col="4" content="<div class='content'>2</div>">
            <e-dashboardlayout-panel sizeX="1" sizeY="1" row="1" col="0" content="<div class='content'>3</div>">
            <e-dashboardlayout-panel sizeX="2" sizeY="1" row="2" col="0" content="<div class='content'>4</div>">
            <e-dashboardlayout-panel sizeX="1" sizeY="1" row="2" col="2" content="<div class='content'>5</div>">
            <e-dashboardlayout-panel sizeX="1" sizeY="1" row="2" col="3" content="<div class='content'>6</div>">
    <!-- end of dashboardlayout element -->

   document.addEventListener('DOMContentLoaded', function () {
        // Create instances for dashboardlayout element
        var dashboard = document.getElementById('dashboard_default').ej2_instances[0];
        // Save the current panels
        document.getElementById('save').onclick = function (e) {
        // Restore the initial panels
        document.getElementById('restore').onclick = function (e) {
            dashboard.panels = restoreModel;
    function onCreated() {
            var dashboard = document.getElementById('dashboard_default').ej2_instances[0];
            restoreModel = dashboard.serialize();
            restoreModel[0].content = '<div class="content">0</div>';
            restoreModel[1].content = '<div class="content">1</div>';
            restoreModel[2].content = '<div class="content">2</div>';
            restoreModel[3].content = '<div class="content">3</div>';
            restoreModel[4].content = '<div class="content">4</div>';
            restoreModel[5].content = '<div class="content">5</div>';
            restoreModel[6].content = '<div class="content">6</div>';

    /* DashboardLayout element styles  */
    #dashboard_default .e-panel .e-panel-container .content {
        vertical-align: middle;
        font-weight: 600;
        font-size: 20px;
        text-align: center;
        line-height: 90px;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication.Controllers
    public class HomeController : Controller
        public class spacingModel
            public double[] cellSpacing { get; set; }
        public ActionResult Index()
            spacingModel modelValue = new spacingModel();
            modelValue.cellSpacing = new double[] { 20, 20 };
            return View(modelValue);

Output be like the below.

State maintenance