Defer update in Vue Pivotview component
11 Jun 202410 minutes to read
Defer layout update support allows to update the pivot table component only on demand. On enabling this feature, end user can drag-and-drop fields between row, column, value and filter axes, apply sorting and filtering inside the Field List, resulting in change of pivot report alone but not the pivot table values. Once all operations are performed and on clicking the “Apply” button in the Field List, pivot table will start to update with the last modified report. This also helps in bringing better performance in pivot table component rendering.
The field list can be displayed in two different formats to interact with pivot table. They are:
- In-built Field List (Popup): To display the field list icon in pivot table UI to invoke the built-in dialog.
- Stand-alone Field List (Fixed): To display the field list in a static position within a web page.
In-built Field List (Popup)
To enable deferred updates in the pivot table, set the property allowDeferLayoutUpdate
in pivot table as true. To make a note, the defer update option can be controlled only via Field List during runtime.
<template>
<div id="app">
<ejs-pivotview :dataSourceSettings="dataSourceSettings" :height="height" :showFieldList="showFieldList"
:allowDeferLayoutUpdate="allowDeferLayoutUpdate"> </ejs-pivotview>
</div>
</template>
<script setup>
import { provide } from "vue";
import { PivotViewComponent as EjsPivotview, FieldList } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';
const dataSourceSettings = {
dataSource: pivotData,
expandAll: false,
allowLabelFilter: true,
allowValueFilter: true,
drilledMembers: [{ name: 'Country', items: ['France'] }],
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 showFieldList = true;
const allowDeferLayoutUpdate = true;
provide('pivotview', [FieldList]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>
<template>
<div id="app">
<ejs-pivotview :dataSourceSettings="dataSourceSettings" :height="height" :showFieldList="showFieldList"
:allowDeferLayoutUpdate="allowDeferLayoutUpdate"> </ejs-pivotview>
</div>
</template>
<script>
import { PivotViewComponent, FieldList } 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,
allowLabelFilter: true,
allowValueFilter: true,
drilledMembers: [{ name: 'Country', items: ['France'] }],
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,
showFieldList: true,
allowDeferLayoutUpdate: true
}
},
provide: {
pivotview: [FieldList]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>
Stand-alone Field List (Fixed)
The field list can be rendered in a static position, anywhere in web page layout, like a separate component. To do so, you need to set renderMode
property to Fixed in pivot field list.
To enable deferred updates in the static fieldlist, set the property allowDeferLayoutUpdate
in pivot field list as true. To make a note, the defer update option can be controlled only via Field List during runtime.
To make field list interact with pivot table, you need to use the UpdateView and Update methods for data source update in both field list and pivot table simultaneously.
<template>
<div id="app">
<ejs-pivotview id="pivotview_flist" :height="height" :allowDeferLayoutUpdate="allowDeferLayoutUpdate"></ejs-pivotview>
<ejs-pivotfieldlist id="pivotfieldlist1" :allowDeferLayoutUpdate="allowDeferLayoutUpdate"
:dataSourceSettings="dataSourceSettings" :enginePopulated="fieldEnginePopulated"
:renderMode="renderMode"></ejs-pivotfieldlist>
</div>
</template>
<script setup>
import { PivotViewComponent as EjsPivotview, PivotFieldListComponent as EjsPivotfieldlist } 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 renderMode = "Fixed";
const allowDeferLayoutUpdate = true;
const fieldEnginePopulated = () => {
let fieldlistObj = document.getElementById('pivotfieldlist1').ej2_instances[0];
let pivotGridObj = document.getElementById('pivotview_flist').ej2_instances[0];
if (fieldlistObj.isRequiredUpdate) {
fieldlistObj.updateView(pivotGridObj);
}
pivotGridObj.notify('ui-update', pivotGridObj);
fieldlistObj.notify('tree-view-update', fieldlistObj);
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
#pivotfieldlist1 {
width: 400px;
margin-top: 20px;
}
</style>
<template>
<div id="app">
<ejs-pivotview id="pivotview_flist" :height="height" :allowDeferLayoutUpdate="allowDeferLayoutUpdate"></ejs-pivotview>
<ejs-pivotfieldlist id="pivotfieldlist1" :allowDeferLayoutUpdate="allowDeferLayoutUpdate"
:dataSourceSettings="dataSourceSettings" :enginePopulated="fieldEnginePopulated"
:renderMode="renderMode"></ejs-pivotfieldlist>
</div>
</template>
<script>
import { PivotViewComponent, PivotFieldListComponent } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';
export default {
name: "App",
components: {
"ejs-pivotview": PivotViewComponent,
"ejs-pivotfieldlist": PivotFieldListComponent
},
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,
renderMode: "Fixed",
allowDeferLayoutUpdate: true
}
},
methods: {
fieldEnginePopulated: function (args) {
let fieldlistObj = document.getElementById('pivotfieldlist1').ej2_instances[0];
let pivotGridObj = document.getElementById('pivotview_flist').ej2_instances[0];
if (fieldlistObj.isRequiredUpdate) {
fieldlistObj.updateView(pivotGridObj);
}
pivotGridObj.notify('ui-update', pivotGridObj);
fieldlistObj.notify('tree-view-update', fieldlistObj);
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
#pivotfieldlist1 {
width: 400px;
margin-top: 20px;
}</style>