Having trouble getting help?
Contact Support
Contact Support
State persistence in Vue Pivotview component
11 Jun 20249 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 pivot table is set to true.
<template>
<div id="app">
<ejs-pivotview :dataSourceSettings="dataSourceSettings" :height="height" :showGroupingBar="showGroupingBar"
:enablePersistence="enablePersistence"> </ejs-pivotview>
</div>
</template>
<script setup>
import { provide } from "vue";
import { PivotViewComponent as EjsPivotview, GroupingBar } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';
const dataSourceSettings = {
dataSource: pivotData,
expandAll: false,
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
filters: []
};
const height = 350;
const showGroupingBar = true;
const enablePersistence = true;
provide('pivotview', [GroupingBar]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>
<template>
<div id="app">
<ejs-pivotview :dataSourceSettings="dataSourceSettings" :height="height" :showGroupingBar="showGroupingBar"
:enablePersistence="enablePersistence"> </ejs-pivotview>
</div>
</template>
<script>
import { PivotViewComponent, GroupingBar } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';
export default {
name: "App",
components: {
"ejs-pivotview": PivotViewComponent
},
data() {
return {
dataSourceSettings: {
dataSource: pivotData,
expandAll: false,
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
filters: []
},
height: 350,
showGroupingBar: true,
enablePersistence: true
}
},
provide: {
pivotview: [GroupingBar]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>
Save and Load Pivot Layout
11 Jun 20249 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 pivot table.
<template>
<div id="app">
<ejs-button id="save-btn" :isPrimary="isPrimary" v-on:click="saveBtnClick">Save Layout</ejs-button>
<ejs-button id="load-btn" :isPrimary="isPrimary" v-on:click="loadBtnClick">Load Layout</ejs-button>
<ejs-pivotview id="pivotview" :dataSourceSettings="dataSourceSettings" :height="height"
:showGroupingBar="showGroupingBar" :enablePersistence="enablePersistence"> </ejs-pivotview>
</div>
</template>
<script setup>
import { provide } from "vue";
import { PivotViewComponent as EjsPivotview, GroupingBar } from "@syncfusion/ej2-vue-pivotview";
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";
import { pivotData } from './pivotData.js';
let layout;
const dataSourceSettings = {
dataSource: pivotData,
expandAll: false,
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
filters: []
};
const height = 350;
const showGroupingBar = true;
const enablePersistence = true;
const isPrimary = true;
provide('pivotview', [GroupingBar]);
const saveBtnClick = () => {
let pivotGridObj = document.getElementById('pivotview').ej2_instances[0];
layout = pivotGridObj.getPersistData();
};
const loadBtnClick = () => {
let pivotGridObj = document.getElementById('pivotview').ej2_instances[0];
pivotGridObj.loadPersistData(layout);
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>
<template>
<div id="app">
<ejs-button id="save-btn" :isPrimary="isPrimary" v-on:click="saveBtnClick">Save Layout</ejs-button>
<ejs-button id="load-btn" :isPrimary="isPrimary" v-on:click="loadBtnClick">Load Layout</ejs-button>
<ejs-pivotview id="pivotview" :dataSourceSettings="dataSourceSettings" :height="height"
:showGroupingBar="showGroupingBar" :enablePersistence="enablePersistence"> </ejs-pivotview>
</div>
</template>
<script>
import { PivotViewComponent, GroupingBar } from "@syncfusion/ej2-vue-pivotview";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
import { pivotData } from './pivotData.js';
let layout;
export default {
name: "App",
components: {
"ejs-button": ButtonComponent,
"ejs-pivotview": PivotViewComponent
},
data() {
return {
dataSourceSettings: {
dataSource: pivotData,
expandAll: false,
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
filters: []
},
height: 350,
showGroupingBar: true,
enablePersistence: true,
isPrimary: true
}
},
provide: {
pivotview: [GroupingBar]
},
methods: {
saveBtnClick: function () {
let pivotGridObj = document.getElementById('pivotview').ej2_instances[0];
this.layout = pivotGridObj.getPersistData();
},
loadBtnClick: function () {
let pivotGridObj = document.getElementById('pivotview').ej2_instances[0];
pivotGridObj.loadPersistData(this.layout);
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>