Search results

Show field list when pivot table is empty in Angular Pivot Table component

18 May 2022 / 1 minute to read

When there are no fields in a pivot table’s row, column, value, and filter axes, a field list can still be displayed. To do so, use the dataBound event and call the onShowFieldList method as shown below.

Source
Preview
app.component.ts
app.module.ts
Copied to clipboard
import { Component, OnInit, ViewChild } from '@angular/core';
import { IDataOptions, PivotView, FieldListService } from '@syncfusion/ej2-angular-pivotview';
import { Pivot_Data } from './datasource.ts';

@Component({
  selector: 'app-container',
  providers: [FieldListService],
  // specifies the template string for the pivot table component
  template: `<ejs-pivotview #pivotview id='PivotView' height='350' [dataSourceSettings]=dataSourceSettings
  width=width (dataBound)='ondataBound()' showFieldList='true'></ejs-pivotview>`
})
export class AppComponent implements OnInit {
    public width: string;
    public dataSourceSettings: IDataOptions;

    @ViewChild('pivotview',{static: false})
    public pivotGridObj: PivotView;

    ondataBound(): void {
        if (this.pivotGridObj && this.pivotGridObj.dataSourceSettings.values.length === 0) {
            (this.pivotGridObj.pivotFieldListModule.dialogRenderer as any).onShowFieldList();
        }
    }

    ngOnInit(): void {

        this.width = '100%';

        this.dataSourceSettings = {
            dataSource: Pivot_Data,
        };
    }
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { PivotViewAllModule, PivotFieldListAllModule } from '@syncfusion/ej2-angular-pivotview';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        PivotViewAllModule,
        PivotFieldListAllModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }