- Splitter
- Change splitter position dynamically
Contact Support
Splitter in Angular Gantt component
27 Apr 20247 minutes to read
Splitter
In the Gantt component, the Splitter separates the TreeGrid section from the Chart section. You can change the position of the Splitter when loading the Gantt component using the splitterSettings
property. By splitting the TreeGrid from the chart, the width of the TreeGrid and chart sections will vary in the component. The splitterSettings.position
property denotes the percentage of the TreeGrid section’s width to be rendered and this property supports both pixels and percentage values. You can define the splitter position as column index value using the splitterSettings.columnIndex
property. You can also define the splitter position with built-in splitter view modes by using the splitterSettings.view
property. The following list is the possible values for this property:
-
Default
: Shows Grid side and Gantt side. -
Grid
: Shows Grid side alone in Gantt. -
Chart
: Shows chart side alone in Gantt.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Gantt } from '@syncfusion/ej2-gantt';
import { editingData } from './data';
@Component({
imports: [
GanttModule
],
standalone: true,
selector: 'app-root',
template:
`<ejs-gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings" [splitterSettings]="splitterSettings"></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 = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
this.splitterSettings = {
position: "50%"
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Change splitter position dynamically
In Gantt, we can change the splitter position dynamically by using setSplitterPosition
method. Either We can change the splitter position with splitter position or columnIndex values by passing these values as arguments to setSplitterPosition
method. The following code example shows how to use this methods.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { GanttModule } from '@syncfusion/ej2-angular-gantt'
import { DropDownListComponent,DropDownListAllModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component, ViewEncapsulation, OnInit, ViewChild } from '@angular/core';
import { Gantt } from '@syncfusion/ej2-gantt';
import { GanttComponent } from '@syncfusion/ej2-angular-gantt';
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons';
import { ChangeEventArgs } from '@syncfusion/ej2-angular-dropdowns';
import { editingData } from './data';
@Component({
imports: [
GanttModule,DropDownListAllModule
],
standalone: true,
selector: 'app-root',
template:
`<button ejs-button id='changebyposition' (click)='changep()'>Change By Position</button>
<br><br>
<button ejs-button id='changebyindex' (click)='changei()'>Change By Index</button>
<br>
<div style="padding-top: 7px; display: inline-block">Splitter View<ejs-dropdownlist (change)='onChange($event)' [dataSource]='dropData' value='Default' [fields]='fields'></ejs-dropdownlist></div>
<ejs-gantt #gantt id="ganttDefault" height="430px" [dataSource]="data" [taskFields]="taskSettings"></ejs-gantt>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent{
// Data for Gantt
public data?: object[];
public taskSettings?: object;
public dropData?: Object[];
public fields?: Object;
@ViewChild('gantt', {static: true})
public ganttObj?: GanttComponent| any;
public ngOnInit(): void {
this.data = editingData;
this.taskSettings = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
};
this.dropData = [
{ id: 'Default', mode: 'Default' },
{ id: 'Grid', mode: 'Grid' },
{ id: 'Chart', mode: 'Chart' },
];
this.fields = { text: 'mode', value: 'id' };
}
changep(): void {
this.ganttObj.setSplitterPosition('50%', 'position');
};
changei(): void {
this.ganttObj.setSplitterPosition(1, 'columnIndex');
};
onChange(e: ChangeEventArgs): any{
let viewType: any = <string>e.value;
this.ganttObj.setSplitterPosition(viewType, 'view');
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));