Hide empty headers in Angular Pivotview component
22 Aug 20252 minutes to read
When the raw data for a particular field is not defined, it will be shown as ‘Undefined’ in the pivot table headers. You can hide those headers by setting the showHeaderWhenEmpty
property to false in the pivot table.
For example, when the raw data contains “United Kingdom” for the ‘Country’ field but the “State” field is undefined, the header displays as “United Kingdom » Undefined”. Here, you can hide those ‘Undefined’ headers using the showHeaderWhenEmpty
property.
By default, this property is set to true.
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 { pivotNullData } 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></ejs-pivotview></div>`
})
export class AppComponent {
public width?: string;
public dataSourceSettings?: DataSourceSettingsModel;
ngOnInit(): void {
this.width = '100%';
this.dataSourceSettings = {
dataSource: pivotNullData as IDataSet[],
expandAll: false,
rows: [{ name: 'Country' }, { name: 'State'}],
columns: [{ name: 'Product', showNoDataItems: true }, { name: 'Date' }],
values: [{ name: 'Amount' }, { name: 'Quantity' }],
showHeaderWhenEmpty: false
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));