[app.component.html]
<button ejs-button (click)="changeTimeline()"> Update Timeline </button>
<ejs-gantt #gantt id="ganttDefault"
//……
</ejs-gantt>
[app.component.ts]
export class AppComponent {
@ViewChild('gantt', {static: true})
public ganttObj: GanttComponent;
public ngOnInit(): void {
//……
}
changeTimeline(): void {
var task = this.ganttObj.getRecordByID(12);
var taskbarLeft = task.ganttProperties.left;
var taskbarWidth = task.ganttProperties.width;
var rowElement = this.ganttObj.getRowByID(task.TaskID);
var labelElement = rowElement.querySelector('.e-right-label-container');
var totalLeft = taskbarLeft + taskbarWidth + labelElement.offsetWidth + 25; // 25 is the margin value
var newDate: Date = this.getDateByLeft(totalLeft);
this.ganttObj.updateProjectDates(this.ganttObj.timelineModule.timelineStartDate, newDate);
} |
Could you provide a method for doing the same but for the left label?
Hi John Doe,
We are currently working on your query and will share further details within two business days on October 4, 2022. Until then we appreciate your patience.
Regards,
Gopinath M
Hi John Doe,
Thanks for the patience.
We have prepared a sample to achieve your requirement. In this sample, we have modified the same with left label using a custom method getDateByRight() also we must modify the newDate and timelineEndDate value inside the updateProjectDates method. We have attached a sample and code snippets for your reference, please check the below sample and code snippets for more details.
Code snippets:
changeTimeline(): void { var task = this.ganttObj.getRecordByID(12); var taskbarLeft = task.ganttProperties.left; var taskbarWidth = task.ganttProperties.width; var rowElement = this.ganttObj.getRowByID(task.TaskID); var labelElement = rowElement.querySelector('.e-left-label-container'); var totalLeft = taskbarLeft + taskbarWidth + labelElement.offsetWidth + 25; //Element's margin left; var newDate: Date = this.getDateByRight(totalLeft); this.ganttObj.updateProjectDates( newDate, this.ganttObj.timelineModule.timelineEndDate ); } //… public getDateByRight(right: number): Date { let pEndDate: Date = new Date( this.ganttObj.timelineModule.timelineEndDate.toString() ); let milliSecondsPerPixel: number = (24 * 60 * 60 * 1000) / this.ganttObj.perDayWidth; pEndDate.setTime(pEndDate.getTime() - right * milliSecondsPerPixel); let tierMode: string = this.ganttObj.timelineModule.bottomTier !== 'None' ? this.ganttObj.timelineModule.topTier : this.ganttObj.timelineModule.bottomTier; //... } return pEndDate; } |
Sample: https://stackblitz.com/edit/angular-z7rsmw-b9pvb7?file=app.component.ts
Regards,
Gopinath M