Excel-like Filtering in Angular Gantt Chart Component

18 Nov 201824 minutes to read

The Excel-like filter in Angular Gantt Chart component enables column-level filtering similar to Microsoft Excel. It supports sorting, clearing filters, and applying advanced conditions through a submenu available in each column header. This feature is highly effective for working with large datasets and applying multiple filter criteria.

To enable this feature, configure filterSettings.type as Excel and set allowFiltering to true.

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { GanttModule, FilterService, SortService} from '@syncfusion/ej2-angular-gantt';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [GanttModule],
  providers: [FilterService, SortService],
  encapsulation: ViewEncapsulation.None,
  template: `
    <ejs-gantt height="370px" [allowSorting]="true" [allowFiltering]="true" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [splitterSettings]="splitterSettings" [filterSettings]="filterSettings">
    </ejs-gantt>`
})

export class AppComponent implements OnInit {
  public data?: object[];
  public taskSettings?: object;
  public columns?: object[];
  public splitterSettings?: object;
  public filterSettings?: object;

  ngOnInit(): void {
    this.data = [
      { TaskID: 1, TaskName: 'Project Initiation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskID: 2, TaskName: 'Identify Site location', StartDate: new Date('04/02/2019'), Duration: 4, ParentID: 1, Progress: 50 },
      { TaskID: 3, TaskName: 'Perform Soil test', StartDate: new Date('04/02/2019'), Duration: 4, ParentID: 1, Progress: 50 },
      { TaskID: 4, TaskName: 'Soil test approval', StartDate: new Date('04/02/2019'), Duration: 4, ParentID: 1, Progress: 50 },
      { TaskID: 5, TaskName: 'Project Estimation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskID: 6, TaskName: 'Develop floor plan for estimation', StartDate: new Date('04/04/2019'), Duration: 3, ParentID: 5, Progress: 50 },
      { TaskID: 7, TaskName: 'List materials', StartDate: new Date('04/04/2019'), Duration: 3, ParentID: 5, Progress: 50 },
      { TaskID: 8, TaskName: 'Estimation approval', StartDate: new Date('04/04/2019'), Duration: 3, ParentID: 5, Progress: 50 }
    ];
    this.taskSettings = {
      id: 'TaskID',
      name: 'TaskName',
      startDate: 'StartDate',
      duration: 'Duration',
      progress: 'Progress',
      parentID: 'ParentID'
    };
    this.columns = [
      { field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '120' },
      { field: 'TaskName', headerText: 'Task Name', width: '250' },
      { field: 'StartDate', headerText: 'Start Date', width: '150' },
      { field: 'Duration', headerText: 'Duration', width: '150' },
      { field: 'Progress', headerText: 'Progress', width: '150' }
    ];
    this.splitterSettings = {
      columnIndex: 3
    };
    this.filterSettings = {
      type: 'Excel'
    };
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Show customized text in checkbox list data

To customize the text displayed in a checkbox list, use filterItemTemplate and assign it to the desired column. This allows rendering custom content for each item in the filter list.

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { GanttModule, FilterService, SortService } from '@syncfusion/ej2-angular-gantt';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [GanttModule],
  providers: [FilterService, SortService],
  encapsulation: ViewEncapsulation.None,
  template: `
    <ejs-gantt height="450px" width="700px" [dataSource]="data" [taskFields]="taskSettings" [allowFiltering]="true" [filterSettings]="filterSettings" [splitterSettings]="splitterSettings">
      <e-columns>
        <e-column field="TaskID" headerText="Task ID" width="100" [isPrimaryKey]="true"></e-column>
        <e-column field="TaskName" headerText="Task Name" width="150"></e-column>
        <e-column field="StartDate" headerText="Start Date" width="150"></e-column>
        <e-column field="EndDate" headerText="End Date" width="150"></e-column>
        <e-column field="Duration" headerText="Duration" width="150"></e-column>
        <e-column field="Progress" headerText="Progress" width="150"></e-column>
        <e-column field="IsCompleted" headerText="Status" width="150" displayAsCheckbox="true">
          <ng-template #filterItemTemplate let-data>
            <span></span>
          </ng-template>
        </e-column>
      </e-columns>
    </ejs-gantt>`
})

export class AppComponent implements OnInit {
  public data?: object[];
  public taskSettings?: object;
  public splitterSettings?: object;
  public filterSettings?: object;

  ngOnInit(): void {
    this.data = [
      { TaskID: 1, TaskName: 'Project Management', StartDate: new Date('2023-04-02'), EndDate: new Date('2023-04-12'), Duration: 10, Progress: 40, IsCompleted: true },
      { TaskID: 2, TaskName: 'Identify Site location', StartDate: new Date('2023-04-02'), Duration: 4, Progress: 100, IsCompleted: true, ParentID: 1 },
      { TaskID: 3, TaskName: 'Perform Soil test', StartDate: new Date('2023-04-02'), Duration: 4, Progress: 50, IsCompleted: true, ParentID: 1 },
      { TaskID: 4, TaskName: 'Soil test approval', StartDate: new Date('2023-04-02'), Duration: 4, Progress: 100, IsCompleted: true, ParentID: 1 },
      { TaskID: 5, TaskName: 'Project Estimation', StartDate: new Date('2023-04-02'), EndDate: new Date('2023-04-10'), Duration: 8, Progress: 60, IsCompleted: false },
      { TaskID: 6, TaskName: 'Develop floor plan', StartDate: new Date('2023-04-04'), Duration: 3, Progress: 100, IsCompleted: false, ParentID: 5 },
      { TaskID: 7, TaskName: 'List materials', StartDate: new Date('2023-04-04'), Duration: 3, Progress: 40, IsCompleted: false, ParentID: 5 }
    ];

    this.taskSettings = {
      id: 'TaskID',
      name: 'TaskName',
      startDate: 'StartDate',
      endDate: 'EndDate',
      duration: 'Duration',
      progress: 'Progress',
      parentID: 'ParentID'
    };

    this.splitterSettings = {
      columnIndex: 3
    };

    this.filterSettings = {
      type: 'Excel'
    };
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Hide Excel filter dialog elements

You can hide elements such as the context menu, search box, sorting options, and checkbox list in the Gantt Excel filter dialog using the following CSS:

.e-gantt .e-excelfilter .e-contextmenu-wrapper {
    display: none;
}

If you want to hide only the built-in sorting options (ascending, descending, and separator), apply the following CSS:

 .e-excel-ascending,
 .e-excel-descending,
 .e-separator.e-excel-separator {
    display: none;
  }
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { GanttModule,  FilterService, SortService } from '@syncfusion/ej2-angular-gantt';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [GanttModule],
  providers: [FilterService, SortService],
  encapsulation: ViewEncapsulation.None,
  template: `
    <ejs-gantt height="370px" [allowFiltering]="true" [allowSorting]="true" [dataSource]="data" [taskFields]="taskSettings" [columns]="columns" [splitterSettings]="splitterSettings" [filterSettings]="filterSettings">
    </ejs-gantt>`,
 styles: [`
    .e-gantt .e-excelfilter .e-contextmenu-wrapper {
      display: none;
    }
  `]
})

export class AppComponent implements OnInit {
  public data?: object[];
  public taskSettings?: object;
  public columns?: object[];
  public splitterSettings?: object;
  public filterSettings?: object;

  ngOnInit(): void {
    this.data = [
      { TaskID: 1, TaskName: 'Project Initiation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskID: 2, TaskName: 'Identify Site location', StartDate: new Date('04/02/2019'), Duration: 4, ParentID: 1, Progress: 50 },
      { TaskID: 3, TaskName: 'Perform Soil test', StartDate: new Date('04/02/2019'), Duration: 4, ParentID: 1, Progress: 50 },
      { TaskID: 4, TaskName: 'Soil test approval', StartDate: new Date('04/02/2019'), Duration: 4, ParentID: 1, Progress: 50 },
      { TaskID: 5, TaskName: 'Project Estimation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskID: 6, TaskName: 'Develop floor plan for estimation', StartDate: new Date('04/04/2019'), Duration: 3, ParentID: 5, Progress: 50 },
      { TaskID: 7, TaskName: 'List materials', StartDate: new Date('04/04/2019'), Duration: 3, ParentID: 5, Progress: 50 },
      { TaskID: 8, TaskName: 'Estimation approval', StartDate: new Date('04/04/2019'), Duration: 3, ParentID: 5, Progress: 50 }
    ];
    this.taskSettings = {
      id: 'TaskID',
      name: 'TaskName',
      startDate: 'StartDate',
      duration: 'Duration',
      progress: 'Progress',
      parentID: 'ParentID'
    };
    this.columns = [
      { field: 'TaskID', headerText: 'Task ID', textAlign: 'Left', width: '120' },
      { field: 'TaskName', headerText: 'Task Name', width: '250' },
      { field: 'StartDate', headerText: 'Start Date', width: '150' },
      { field: 'Duration', headerText: 'Duration', width: '150' },
      { field: 'Progress', headerText: 'Progress', width: '150' }
    ];
    this.splitterSettings = {
      columnIndex: 3
    };
    this.filterSettings = {
      type: 'Excel'
    };
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Customize filter choice count

The Angular Gantt Chart component displays up to 1000 distinct values per column in the filter dialog by default. These values are taken from the first 1000 records bound to the component and shown as checkbox list items to maintain optimal performance. Additional values can be accessed using the search option within the filter dialog.

To customize this behavior, the filterChoiceCount property can be adjusted to increase or decrease the number of distinct values displayed, depending on the dataset size and filtering requirements.

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { GanttModule, FilterService, ActionBeginArgs } from '@syncfusion/ej2-angular-gantt';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [GanttModule],
  providers: [FilterService],
  encapsulation: ViewEncapsulation.None,
  template: `
    <ejs-gantt height="370px" [allowFiltering]="true" [dataSource]="localData" [taskFields]="taskSettings" [columns]="columns" [splitterSettings]="splitterSettings" [filterSettings]="filterSettings" (actionBegin)="actionBegin($event)">
    </ejs-gantt>`
})

export class AppComponent implements OnInit {
  public localData: object[] = [];
  public taskSettings: object = {};
  public columns: object[] = [];
  public splitterSettings: object = {};
  public filterSettings: object = {};

  ngOnInit(): void {
    this.localData = [
      { TaskId: 1, TaskName: 'Project Initiation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskId: 2, TaskName: 'Identify Site location', StartDate: new Date('04/02/2019'), Duration: 4, ParentId: 1, Progress: 50 },
      { TaskId: 3, TaskName: 'Perform Soil test', StartDate: new Date('04/02/2019'), Duration: 4, ParentId: 1, Progress: 50 },
      { TaskId: 4, TaskName: 'Soil test approval', StartDate: new Date('04/02/2019'), Duration: 4, ParentId: 1, Progress: 50 },
      { TaskId: 5, TaskName: 'Project Estimation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskId: 6, TaskName: 'Develop floor plan for estimation', StartDate: new Date('04/04/2019'), Duration: 3, ParentId: 5, Progress: 50 },
      { TaskId: 7, TaskName: 'List materials', StartDate: new Date('04/04/2019'), Duration: 3, ParentId: 5, Progress: 50 },
      { TaskId: 8, TaskName: 'Estimation approval', StartDate: new Date('04/04/2019'), Duration: 3, ParentId: 5, Progress: 50 }
    ];
    this.taskSettings = {
      id: 'TaskId',
      name: 'TaskName',
      startDate: 'StartDate',
      endDate: 'EndDate',
      duration: 'Duration',
      progress: 'Progress',
      parentID: 'ParentId',
      dependency: 'Predecessor'
    };
    this.columns = [
      { field: 'TaskId', headerText: 'Task ID', width: '120' },
      { field: 'TaskName', headerText: 'Project Activity', width: '250', clipMode: 'EllipsisWithTooltip' },
      { field: 'StartDate', headerText: 'Planned Start Date', width: 200 },
      { field: 'Duration', headerText: 'Duration', width: 160 },
      { field: 'Progress', headerText: 'Completion (%)', width: 200 }
    ];
    this.splitterSettings = {
      columnIndex: 3
    };
    this.filterSettings = {
      type: 'Excel'
    };
  }

  public actionBegin(args: ActionBeginArgs): void {
    if (args.requestType === "filterchoicerequest" || args.requestType === "filtersearchbegin") {
      (args as any).filterChoiceCount = 1000;
    }
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Bind custom remote data source for Excel-like filtering

You can dynamically bind a custom remote data source to the Excel filter in the Gantt Chart component by using a DataManager with WebApiAdaptor. This can be done by assigning the data source directly or storing fetched data in a global variable. Then, bind it to the filter module’s dataSource within the actionBegin event when requestType is filterBeforeOpen.

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { GanttModule, FilterService } from '@syncfusion/ej2-angular-gantt';
import { DataManager, WebApiAdaptor } from '@syncfusion/ej2-data';
import { FilterEventArgs } from '@syncfusion/ej2-angular-grids';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [GanttModule],
  providers: [FilterService],
  encapsulation: ViewEncapsulation.None,
  template: `
    <ejs-gantt height="370px" [allowFiltering]="true" [dataSource]="localData" [taskFields]="taskSettings" [columns]="columns" [splitterSettings]="splitterSettings" [filterSettings]="filterSettings" (actionBegin)="actionBegin($event)">
    </ejs-gantt>
  `
})
export class AppComponent implements OnInit {
  public localData: object[] = [];
  public taskSettings: object = {};
  public columns: object[] = [];
  public splitterSettings: object = {};
  public filterSettings: object = {};

  ngOnInit(): void {
    this.localData = [
      { TaskId: 1, TaskName: 'Project Initiation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskId: 2, TaskName: 'Identify Site location', StartDate: new Date('04/02/2019'), Duration: 4, ParentId: 1, Progress: 50 },
      { TaskId: 3, TaskName: 'Perform Soil test', StartDate: new Date('04/02/2019'), Duration: 4, ParentId: 1, Progress: 50 },
      { TaskId: 4, TaskName: 'Soil test approval', StartDate: new Date('04/02/2019'), Duration: 4, ParentId: 1, Progress: 50 },
      { TaskId: 5, TaskName: 'Project Estimation', StartDate: new Date('04/02/2019'), EndDate: new Date('04/21/2019') },
      { TaskId: 6, TaskName: 'Develop floor plan for estimation', StartDate: new Date('04/04/2019'), Duration: 3, ParentId: 5, Progress: 50 },
      { TaskId: 7, TaskName: 'List materials', StartDate: new Date('04/04/2019'), Duration: 3, ParentId: 5, Progress: 50 },
      { TaskId: 8, TaskName: 'Estimation approval', StartDate: new Date('04/04/2019'), Duration: 3, ParentId: 5, Progress: 50 }
    ];
    this.taskSettings = {
      id: 'TaskId',
      name: 'TaskName',
      startDate: 'StartDate',
      endDate: 'EndDate',
      duration: 'Duration',
      progress: 'Progress',
      parentID: 'ParentId',
      dependency: 'Predecessor'
    };
    this.columns = [
      { field: 'TaskId', headerText: 'Task ID', width: '120' },
      { field: 'TaskName', headerText: 'Project Activity', width: '250', clipMode: 'EllipsisWithTooltip' },
      { field: 'StartDate', headerText: 'Planned Start Date', width: 200 },
      { field: 'Duration', headerText: 'Duration', width: 160 },
      { field: 'Progress', headerText: 'Completion (%)', width: 200 }
    ];
    this.splitterSettings = {
      columnIndex: 3
    };
    this.filterSettings = {
      type: 'Excel'
    };
  }

  public actionBegin(args: FilterEventArgs): void {
    if (args.requestType === 'filterBeforeOpen') {
      const hostUrl = 'https://ej2services.syncfusion.com/angular/development/api/GanttWebApiRemoteData';
      (args as any).filterModel.options.dataSource.josn = new DataManager({
        url: hostUrl,
        adaptor: new WebApiAdaptor(),
        crossDomain: true
      });
    }
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));