Contact Support
Row spanning in Angular Gantt component
1 Jun 20244 minutes to read
The Gantt provides an option to span grid row cells, allowing you to merge two or more cells in a row into a single cell. This feature can be useful in scenarios where you want to display information that spans across multiple rows, but want to avoid repeating the same information in each row.
To achieve this, you need to define the rowSpan attribute to span cells in the queryCellInfo event. The rowSpan
attribute is used to specify the number of rows that the current cell should span.
The queryCellInfo
event is triggered for each grid cell in the gantt, allowing you to customize the cells in row. By handling this event, you can set the rowSpan
attribute for a cell to achieve row spanning.
In the following demo, Soil test approval cell is spanned to two rows in the TaskName column.
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { GanttModule } from '@syncfusion/ej2-angular-gantt';
import { GanttData } from './data';
@Component({
imports: [
GanttModule,
],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt id="ganttDefault" 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>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public splitterSettings?: object;
public 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: any) {
if (args.data['TaskID'] == 4 && args.column.field === 'TaskName') {
args.rowSpan = 2;
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));