Row Spanning in Angular Gantt Chart Component
18 Nov 20183 minutes to read
The Angular Gantt Chart component supports row cell spanning, allowing multiple cells in a row to merge into a single cell. This is useful for displaying shared information across rows without duplication.
To enable row spanning, use the rowSpan attribute inside the queryCellInfo event. This event is triggered for each grid cell, where you can define the number of rows a cell should span based on its data.
In the example below, the Soil test approval cell spans across two rows in the TaskName column.
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Column, GanttModule, QueryCellInfoEventArgs } from '@syncfusion/ej2-angular-gantt';
import { GanttData } from './data';
@Component({
selector: 'app-root',
standalone: true,
imports: [GanttModule],
encapsulation: ViewEncapsulation.None,
template: `
<ejs-gantt height="430px" [dataSource]="data" [treeColumnIndex]="1" [taskFields]="taskSettings" [splitterSettings]="splitterSettings" (queryCellInfo)="queryCellInfo($event)">
<e-columns>
<e-column field="TaskID" headerText="Task ID" textAlign="Right" width="90"></e-column>
<e-column field="TaskName" headerText="Task Name" textAlign="Left" width="290"></e-column>
<e-column field="StartDate" headerText="Start Date" textAlign="Right" width="120"></e-column>
<e-column field="Duration" headerText="Duration" textAlign="Right" width="90"></e-column>
<e-column field="Progress" headerText="Progress" textAlign="Right" width="120"></e-column>
</e-columns>
</ejs-gantt>`
})
export class AppComponent implements OnInit {
public data: object[] = [];
public taskSettings!: object;
public splitterSettings!: object;
ngOnInit(): void {
this.data = GanttData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
endDate: 'EndDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
this.splitterSettings = {
position: '75%'
};
}
public queryCellInfo(args: QueryCellInfoEventArgs): void {
if ((args.data as GanttTask)['TaskID'] === 4 && (args.column as Column).field === 'TaskName') {
args.rowSpan = 2;
}
}
}
export interface GanttTask {
TaskID: number;
TaskName: string;
StartDate: Date;
Duration: number;
Progress: number;
subtasks?: GanttTask[];
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));