Having trouble getting help?
Contact Support
Contact Support
State Persistence
17 Feb 20222 minutes to read
State persistence allows user to maintain the current state of the component along with its report bounded in the browser local storage (cookie). Even if the browser is refreshed or if you move to the next page within the browser, components state will be persisted. State persistence stores the Pivot Table object in the local storage when EnablePersistence
property in PivotView
class is set to true.
@Html.EJS().PivotView("PivotView").Height(300).DataSourceSettings(dataSource => dataSource.DataSource((IEnumerable<object>)ViewBag.DataSource).ExpandAll(false)
.Rows(rows =>
{
rows.Name("Country").Add(); rows.Name("Products").Add();
}).Columns(columns =>
{
columns.Name("Year").Caption("Year").Add(); columns.Name("Quarter").Add();
}).Values(values =>
{
values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Add();
})).EnablePersistence(true).ShowGroupingBar(true).Render()
public ActionResult Index()
{
var data = GetPivotData();
ViewBag.DataSource = data;
return View();
}
Save and Load Pivot Layout
17 Feb 20222 minutes to read
You can save the current layout of the pivot table by using getPersistData
in string format. The saved layout can be loaded to pivot table any time by passing the saved data as a parameter to loadPersistData
method in the PivotView
.
@using Syncfusion.EJ2.PivotView
@Html.EJS().Button("save").Content("Save Layout").IsPrimary(true).Render()
@Html.EJS().Button("load").Content("Load Layout").IsPrimary(true).Render()
@Html.EJS().PivotView("PivotView").Height(300).DataSourceSettings(dataSource => dataSource.DataSource((IEnumerable<object>)ViewBag.DataSource).ExpandAll(false)
.Rows(rows =>
{
rows.Name("Country").Add(); rows.Name("Products").Add();
}).Columns(columns =>
{
columns.Name("Year").Caption("Year").Add(); columns.Name("Quarter").Add();
}).Values(values =>
{
values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Add();
})).ShowGroupingBar(true).ShowFieldList(true).Render()
<script>
var pivotObj;
var pivotLayout;
document.getElementById('save').onclick = function () {
pivotObj = document.getElementById('PivotView').ej2_instances[0];
pivotLayout = pivotObj.getPersistData();
}
document.getElementById('load').onclick = function () {
pivotObj = document.getElementById('PivotView').ej2_instances[0];
pivotObj.loadPersistData(pivotLayout);
}
</script>
public ActionResult Index()
{
var data = GetPivotData();
ViewBag.DataSource = data;
return View();
}