- Home
- Forum
- ASP.NET MVC - EJ 2
- Edit start/end date only
Edit start/end date only
When i try to edit task's start date also end date is moved by the same amount, i want to change only start date, but not end date.
Hi Antek,
Greetings from Syncfusion Support,
We
would like to clarify the behavior of the Gantt chart. When the startDate is
changed, the endDate is also updated accordingly, which is the expected
behavior of the Gantt chart.
To handle this behavior, we suggest using the actionBegin event in the Gantt chart. This event is triggered during cell or dialog editing, allowing you to modify the endDate and duration based on the previous value. This ensures that the taskbar is updated according to the previous values.
Below is the code snippet and sample for your reference:
|
@Html.EJS().Gantt("Gantt").DataSource((IEnumerable<object>)ViewBag.dataSource).Height("450px").TaskFields(ts => ts.Id("TaskId").Name( "TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress").Child("SubTasks")).EditSettings(es => es.AllowEditing(true).Mode(Syncfusion.EJ2.Gantt.EditMode.Auto)).ActionBegin("actionBegin").Render()
<script> var previousStartDateValue; var previousEndDateValue; function actionBegin(args) { var gantt = document.getElementById("Gantt").ej2_instances[0]; if(args.columnName == "StartDate" && args.type == "save"){ previousStartDateValue = args.previousValue; previousEndDateValue = args.rowData.EndDate; } if(args.requestType == "beforeOpenEditDialog"){ previousStartDateValue = args.rowData.StartDate; previousEndDateValue = args.rowData.EndDate; } if(args.requestType == "beforeSave"){ const prevDate = new Date(previousStartDateValue); const currentDate = new Date(args.data.StartDate); if (prevDate.getTime() !== currentDate.getTime()) { args.data.ganttProperties.duration = gantt.dataOperation.getDuration(args.data.StartDate, previousEndDateValue, args.data.ganttProperties.durationUnit, args.data.ganttProperties.isAutoSchedule, args.data.ganttProperties.isMilestone); args.data.ganttProperties.endDate = previousEndDateValue; } } } </script> |
Sample attached as zip file.
For more information, you may refer to the
following link:
https://ej2.syncfusion.com/vue/documentation/api/gantt/#actionbegin
Please contact us if you need any further assistance.
Regards,
Ajithkumar G
Attachment: GanttMVC_6e4254f3.zip
- 1 Reply
- 2 Participants
-
AO Antek Olszewski
- Jan 8, 2025 12:48 PM UTC
- Jan 9, 2025 01:27 PM UTC