Defer Update in Angular Pivot Table
18 Aug 202610 minutes to read
Defer layout update support allows updating the pivot table component only on demand, significantly improving performance for complex data operations. When this feature is enabled, users can drag-and-drop fields between row, column, value, and filter axes and apply sorting and filtering inside the Field List. These changes update the pivot report configuration without immediately updating the pivot table values. Once all operations are performed and the Apply button is clicked in the Field List, the pivot table updates with the final modified report. This approach reduces multiple unnecessary renders and brings better performance, especially when working with large datasets or performing multiple field operations.
The field list can be displayed in two different formats to interact with the pivot table:
- In-built Field List (Popup): Displays the field list icon in the pivot table UI to invoke the built-in dialog.
- Stand-alone Field List (Fixed): Displays 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 allowDeferLayoutUpdate property to true in PivotView. Note that the defer update option can only be controlled via the Field List at runtime.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { PivotViewAllModule, PivotFieldListAllModule } from '@syncfusion/ej2-angular-pivotview'
import { Component } from '@angular/core';
import { IDataSet, PivotView, FieldListService } from '@syncfusion/ej2-angular-pivotview';
import { Pivot_Data } from './datasource';
import { DataSourceSettingsModel } from '@syncfusion/ej2-pivotview/src/model/datasourcesettings-model';
@Component({
imports: [
PivotViewAllModule,
PivotFieldListAllModule
],
standalone: true,
selector: 'app-container',
providers: [FieldListService],
// specifies the template string for the pivot table component
template: `<div style="height: 480px;"><ejs-pivotview #pivotview id='PivotView' height='350' [dataSourceSettings]=dataSourceSettings showFieldList='true' [width]=width allowDeferLayoutUpdate='true'></ejs-pivotview></div>`
})
export class AppComponent {
public width?: string;
public dataSourceSettings?: DataSourceSettingsModel;
ngOnInit(): void {
this.width = '100%';
this.dataSourceSettings = {
dataSource: Pivot_Data as IDataSet[],
expandAll: false,
allowLabelFilter: true,
allowValueFilter: true,
enableSorting: 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: []
};
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Stand-alone Field List (Fixed)
The field list can be rendered in a static position anywhere in the web page layout, functioning as a separate component. To achieve this, set the renderMode property to Fixed in PivotFieldList.
To enable deferred updates in the static field list, set the allowDeferLayoutUpdate property to true in PivotFieldList. Note that the defer update option can only be controlled via the Field List at runtime.
To make the field list interact with the pivot table, use the
updateViewandupdatemethods to synchronize data source updates between both the field list and pivot table components simultaneously.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { PivotViewAllModule, PivotFieldListAllModule } from '@syncfusion/ej2-angular-pivotview'
import { Component, ViewChild } from '@angular/core';
import { PivotFieldListComponent, PivotViewComponent, FieldListService, IDataSet,
EnginePopulatedEventArgs } from '@syncfusion/ej2-angular-pivotview';
import { Browser, setStyleAttribute, prepend } from '@syncfusion/ej2-base';
import { GridSettings } from '@syncfusion/ej2-pivotview/src/pivotview/model/gridsettings';
import { Pivot_Data } from './datasource';
import { DataSourceSettingsModel } from '@syncfusion/ej2-pivotview/src/model/datasourcesettings-model';
@Component({
imports: [
PivotViewAllModule,
PivotFieldListAllModule
],
standalone: true,
selector: 'app-container',
providers: [FieldListService],
styleUrls: ['./app.component.css'],
// specifies the template string for the pivot table component
template: `<ejs-pivotfieldlist #pivotfieldlist id='PivotFieldList' [dataSourceSettings]=dataSourceSettings renderMode="Fixed" (enginePopulated)='afterPopulate($event)' allowDeferLayoutUpdate='true' allowCalculatedField='true' (load)='onLoad()' (dataBound)='ondataBound()'></ejs-pivotfieldlist><ejs-pivotview #pivotview id='PivotViewFieldList' allowDeferLayoutUpdate='true' width='99%' height='530' (enginePopulated)='afterEnginePopulate($event)' [gridSettings]='gridSettings'></ejs-pivotview>`
})
export class AppComponent {
public dataSourceSettings?: DataSourceSettingsModel;
public gridSettings?: GridSettings;
@ViewChild('pivotview', {static: false})
public pivotGridObj?: PivotViewComponent;
@ViewChild('pivotfieldlist')
public fieldlistObj?: PivotFieldListComponent;
afterPopulate(arge: EnginePopulatedEventArgs): void {
if ((this.fieldlistObj as PivotFieldListComponent).isRequiredUpdate) {
(this.fieldlistObj as PivotFieldListComponent).updateView(this.pivotGridObj as PivotViewComponent );
}
this.pivotGridObj?.notify('ui-update', this.pivotGridObj);
(this.fieldlistObj as PivotFieldListComponent).notify('tree-view-update', this.fieldlistObj as PivotFieldListComponent);
}
afterEnginePopulate(args: EnginePopulatedEventArgs): void {
if (this.fieldlistObj && this.pivotGridObj) {
this.fieldlistObj.update(this.pivotGridObj);
}
}
onLoad(): void {
if (Browser.isDevice) {
(this.fieldlistObj as PivotFieldListComponent).renderMode = 'Popup';
(this.fieldlistObj as PivotFieldListComponent).target = '.control-section';
(document.getElementById('PivotFieldList') as HTMLElement).removeAttribute('style');
setStyleAttribute(document.getElementById('PivotFieldList') as HTMLElement, {
'height': 0,
'float': 'left'
});
}
}
ondataBound(): void {
if (Browser.isDevice) {
prepend([document.getElementById('PivotFieldList') as HTMLElement], document.getElementById('PivotView') as HTMLElement);
}
}
ngOnInit(): void {
this.gridSettings = {
columnWidth: 140
} as GridSettings;
this.dataSourceSettings = {
dataSource: Pivot_Data as IDataSet[],
expandAll: false,
enableSorting: true,
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: []
};
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));