Task Scheduling with Duration Units in ASP.NET MVC Gantt Chart
Duration units
Duration units define how task duration values are interpreted and calculated in the Gantt Chart. Duration units can be configured globally for the entire project or individually for each task.
The Gantt Chart control supports the following duration units:
- Day: Standard for general planning.
- Hour: For detailed task management.
- Minute: For short-duration tasks.
-
Week: Represents a duration calculated using the configured
daysPerWeekvalue. -
Month: Represents a duration calculated using the configured
daysPerMonthvalue.
Configure using:
-
durationUnit: Sets global unit (default:
day). - taskFields.durationUnit: Maps per-task units.
-
daysPerWeek: Specifies the number of working days that constitute one week duration. -
daysPerMonth: Specifies the number of working days that constitute one month duration. - Duration field values: You can specify the duration unit directly in the duration value (for example, “5 minutes”, “2 weeks”, or “1 month”).
The following example maps duration units:
@using Syncfusion.EJ2.Gantt
@(Html.EJS().Gantt("Gantt")
.DataSource((IEnumerable<object>)ViewBag.DataSource)
.Height("450px")
.DaysPerWeek(5)
.DaysPerMonth(20)
.SplitterSettings(new GanttSplitterSettings
{
ColumnIndex = 4
})
.TaskFields(ts => ts
.Id("TaskID")
.Name("TaskName")
.StartDate("StartDate")
.Duration("Duration")
.Progress("Progress")
.DurationUnit("DurationUnit")
.ParentID("ParentID"))
.Render())public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 4,
Progress = 70,
DurationUnit="day"
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 16,
Progress = 50,
DurationUnit = "hour"
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 480,
Progress = 50,
DurationUnit = "minute"
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>()
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 04),
Duration = 24,
Progress = 70,
DurationUnit = "hour"
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 04),
Duration = 3,
Progress = 50,
DurationUnit = "day"
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public string DurationUnit { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}
The default value of the
DurationUnitproperty isday.
Defining duration unit along with duration field
Duration units for the tasks can also be defined along with the duration values, the below code snippet explains the duration unit for a task along with duration value,
@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")).Render()public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = "3days",
Progress = 70,
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = "12hours",
Progress = 50
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = "1800minutes",
Progress = 50
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>()
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 04),
Duration = "480minutes",
Progress = 70
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 04),
Duration = "3days",
Progress = 50
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}
The edit type of the duration column in Gantt is string, to support editing the duration field along with duration units.
Unscheduled Tasks
Unscheduled tasks are planned for a project without any definite schedule dates. The Gantt control supports rendering the unscheduled tasks. You can create or update the tasks with anyone of start date, end date, and duration values or none. You can enable or disable the unscheduled tasks by using the AllowUnscheduledTasks property. The following images represent the various types of unscheduled tasks in Gantt.
Start Date Only

End Date Only

Duration Only

Milestone
A milestone is a task that has no start and end dates, but it has a duration value of zero. It is represented as follows.

Define unscheduled tasks in data source
You can define the various types of unscheduled tasks in the data source as follows,
@Html.EJS().Gantt("Gantt").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").AllowUnscheduledTasks(true).TaskFields(ts =>
ts.Id("TaskId").Name("TaskName").StartDate("StartDate").Duration("Duration").Progress("Progress").EndDate("EndDate")).Render()public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSourceCollection.Add(new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
Duration = 4
});
GanttDataSourceCollection.Add(new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02)
});
GanttDataSourceCollection.Add(new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
EndDate = new DateTime(2019, 04, 08)
});
GanttDataSourceCollection.Add(new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 06),
Progress=50
});
GanttDataSourceCollection.Add(new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
Duration=0
});
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
}
If the
AllowUnscheduledTasksproperty is set to false, then the Gantt control automatically calculates the scheduled date values with a default value of duration 1 and the project start date is considered as the start date for the task.
Working Time Range
In the Gantt control, working hours in a day for a project can be defined by using the DayWorkingTime property. Based on the working hours, automatic date scheduling and duration validations for a task are performed.
The following code snippet explains how to define the working time range for the project in Gantt.
@Html.EJS().Gantt("Gantt").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").TaskFields(ts =>
ts.Id("TaskId").Name("TaskName").StartDate("StartDate").Duration("Duration").Progress("Progress").EndDate(
"EndDate").Child("SubTasks")).TimelineSettings(tl => tl.TopTier(tt => tt.Format("MMM dd, yyyy").Unit(
Syncfusion.EJ2.Gantt.TimelineViewMode.Day)).BottomTier(bt => bt.Unit(Syncfusion.EJ2.Gantt.TimelineViewMode.Hour).Format("h.mm a")
).TimelineUnitSize(60)).DayWorkingTime(dw =>{dw.From(9).To(18).Add();}).Render()public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> ganttData()
{
List<GanttDataSource> GanttDataSourceCollection = new List<GanttDataSource>();
GanttDataSource Record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project initiation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>(),
};
GanttDataSource Child1 = new GanttDataSource()
{
TaskId = 2,
TaskName = "Identify site location",
StartDate = new DateTime(2019, 04, 02),
Duration = 1,
Progress = 70,
};
GanttDataSource Child2 = new GanttDataSource()
{
TaskId = 3,
TaskName = "Perform soil test",
StartDate = new DateTime(2019, 04, 02),
Duration = 1,
Progress = 50
};
GanttDataSource Child3 = new GanttDataSource()
{
TaskId = 4,
TaskName = "Soil test approval",
StartDate = new DateTime(2019, 04, 02),
Duration = 1,
Progress = 50
};
Record1.SubTasks.Add(Child1);
Record1.SubTasks.Add(Child2);
Record1.SubTasks.Add(Child3);
GanttDataSource Record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Project estimation",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 21),
SubTasks = new List<GanttDataSource>()
};
GanttDataSource Child4 = new GanttDataSource()
{
TaskId = 6,
TaskName = "Develop floor plan for estimation",
StartDate = new DateTime(2019, 04, 04),
Duration = 1,
Progress = 70
};
GanttDataSource Child5 = new GanttDataSource()
{
TaskId = 7,
TaskName = "List materials",
StartDate = new DateTime(2019, 04, 04),
Duration = 1,
Progress = 50
};
Record2.SubTasks.Add(Child4);
Record2.SubTasks.Add(Child5);
GanttDataSourceCollection.Add(Record1);
GanttDataSourceCollection.Add(Record2);
return GanttDataSourceCollection;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}The following screen shot shows working time range in Gantt control.

_ Individual tasks can lie between any time within the defined working time range of the project.
_ TheDayWorkingTimeproperty is used to define the working time for the whole project.
Weekend/Non-working days
Non-working days/weekend are used to represent the non-productive days in a project. You can define the non-working days in a week using the WorkWeek property in Gantt.
@Html.EJS().Gantt("Gantt").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").WorkWeek(new string[] { "Sunday",
"Monday", "Tuesday", "Wednesday", "Thursday" }).TaskFields(ts => ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate(
"EndDate").Duration("Duration").Progress("Progress").Child("SubTasks")).HighlightWeekends(true).Render()public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}
By default, Saturdays and Sundays are considered as non-working days/weekend in a project.
In the Gantt control, you can make weekend as working day by setting theIncludeWeekendproperty totrue.
To show or hide weekend in timeline, use timelineSettings.showWeekend property intimelineSettings. To know more aboutshowWeekend, refer here.
Configure days per week and month
The daysPerWeek property specifies how many working days constitute one week, directly impacting how week-based durations are calculated. For example, if daysPerWeek is 5, then 1 week equals 5 working days.
Similarly, the daysPerMonth property specifies how many working days constitute one month, affecting how month-based durations are converted to actual working days for scheduling calculations. For example, if daysPerMonth is 20, then 1 month equals 20 working days.
The following example configures daysPerWeek and daysPerMonth properties:
@using Syncfusion.EJ2.Gantt
<div style="padding-bottom:10px">
<label>Days Per Week:</label>
<input type="number" id="daysPerWeek" value="5" min="1" max="7" />
<label style="margin-left:10px">Days Per Month:</label>
<input type="number" id="daysPerMonth" value="20" min="1" max="31" />
<button id="updateButton">Update</button>
</div>
@(Html.EJS().Gantt("Gantt")
.DataSource((IEnumerable<object>)ViewBag.DataSource)
.Height("380px")
.DaysPerWeek(5)
.DaysPerMonth(20)
.TaskFields(ts => ts
.Id("TaskID")
.Name("TaskName")
.StartDate("StartDate")
.Duration("Duration")
.Progress("Progress")
.DurationUnit("DurationUnit")
.ParentID("ParentID"))
.SplitterSettings(sp => sp.ColumnIndex(4))
.Render())
<script>
document.getElementById('updateButton').addEventListener('click', function () {
var daysPerWeek = parseInt(document.getElementById('daysPerWeek').value);
var daysPerMonth = parseInt(document.getElementById('daysPerMonth').value);
if (daysPerWeek < 1 || daysPerWeek > 7) {
alert('Days per Week must be between 1 and 7');
return;
}
if (daysPerMonth < 1 || daysPerMonth > 31) {
alert('Days per Month must be between 1 and 31');
return;
}
var gantt = document.getElementById('Gantt').ej2_instances[0];
gantt.daysPerWeek = daysPerWeek;
gantt.daysPerMonth = daysPerMonth;
});
</script>public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.DataSource = GetTaskCollection();
return View();
}
public static List<GanttDataSource> GetTaskCollection()
{
return new List<GanttDataSource>()
{
new GanttDataSource
{
TaskID = 1,
TaskName = "Project Planning",
ParentID = null,
StartDate = new DateTime(2019, 4, 2),
EndDate = new DateTime(2019, 4, 21),
IsParent = true
},
new GanttDataSource
{
TaskID = 2,
TaskName = "Planning Phase",
ParentID = 1,
StartDate = new DateTime(2019, 4, 2),
Duration = 1,
DurationUnit = "week",
Progress = 50,
IsParent = false
},
new GanttDataSource
{
TaskID = 3,
TaskName = "Resource Allocation",
ParentID = 1,
StartDate = new DateTime(2019, 4, 9),
Duration = 2,
DurationUnit = "week",
Predecessor = "2FS",
Progress = 70,
IsParent = false
},
new GanttDataSource
{
TaskID = 4,
TaskName = "Design Phase",
ParentID = null,
StartDate = new DateTime(2019, 4, 23),
EndDate = new DateTime(2019, 5, 21),
IsParent = true
},
new GanttDataSource
{
TaskID = 5,
TaskName = "Design Mockups",
ParentID = 4,
StartDate = new DateTime(2019, 4, 23),
Duration = 1,
DurationUnit = "month",
Progress = 60,
IsParent = false
},
new GanttDataSource
{
TaskID = 6,
TaskName = "Design Review",
ParentID = 4,
StartDate = new DateTime(2019, 5, 21),
Duration = 1,
DurationUnit = "week",
Predecessor = "5FS",
Progress = 40,
IsParent = false
},
new GanttDataSource
{
TaskID = 7,
TaskName = "Development",
ParentID = null,
StartDate = new DateTime(2019, 5, 28),
EndDate = new DateTime(2019, 7, 21),
IsParent = true
},
new GanttDataSource
{
TaskID = 8,
TaskName = "Backend Development",
ParentID = 7,
StartDate = new DateTime(2019, 5, 28),
Duration = 2,
DurationUnit = "week",
Progress = 35,
IsParent = false
},
new GanttDataSource
{
TaskID = 9,
TaskName = "Frontend Development",
ParentID = 7,
StartDate = new DateTime(2019, 6, 11),
Duration = 1,
DurationUnit = "month",
Predecessor = "8FS",
Progress = 25,
IsParent = false
},
new GanttDataSource
{
TaskID = 10,
TaskName = "Testing",
ParentID = 7,
StartDate = new DateTime(2019, 7, 9),
Duration = 2,
DurationUnit = "week",
Predecessor = "9FS",
Progress = 10,
IsParent = false
}
};
}
public class GanttDataSource
{
public int TaskID { get; set; }
public string TaskName { get; set; }
public int? ParentID { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public int? Duration { get; set; }
public string DurationUnit { get; set; }
public string Predecessor { get; set; }
public int? Progress { get; set; }
public bool IsParent { get; set; }
}
}Inactive tasks
The inactive task feature allows specific tasks to be excluded from project scheduling calculations while remaining visible in the Gantt chart. This is useful for representing tasks that are temporarily paused, postponed, inactive, or not yet ready for execution without removing them from the project plan.
When mark a task as inactive:
- The task keeps its row, its own start and end dates, and its stored duration.
- The task is excluded from predecessor scheduling, parent date and work roll-up, and critical path calculation.
- Links attached to the task are kept in the data source. They are not deleted when the task becomes inactive.
Enable inactive tasks
To enable inactive task support, inject the InactiveTask module and map a boolean field from the data source to the inActiveState field in taskFields.
When taskFields.inActiveState is mapped, the Gantt Chart component automatically displays an checkbox column in the Gantt Chart to change the task’s active or inactive state. Also, the state can be changed using edit dialog in advanced tab.
The value true in the mapped data source field marks the task inactive.
The following example demonstrates how to configure inactive task support in the Gantt Chart component.
@Html.EJS().Gantt("GanttContainer")
.DataSource((IEnumerable<object>)ViewBag.DataSource)
.Height("640px")
.TreeColumnIndex(1)
.ProjectStartDate("03/30/2025")
.ProjectEndDate("05/04/2025")
.RowHeight(46)
.TaskbarHeight(25)
.ToolbarClick("toolbarClick")
.TaskFields(ts => ts
.Id("TaskID")
.Name("TaskName")
.ParentID("ParentId")
.StartDate("StartDate")
.Duration("Duration")
.Progress("Progress")
.Dependency("Predecessor")
.InActiveState("inActive"))
.LabelSettings(ls => ls
.RightLabel("TaskName"))
.SplitterSettings(sp => sp
.ColumnIndex(2))
.EditSettings(es => es
.AllowAdding(true)
.AllowEditing(true))
.Columns(col =>
{
col.Field("TaskID")
.HeaderText("Task ID")
.Visible(false)
.Width("90")
.Add();
col.Field("TaskName")
.HeaderText("Task Name")
.Width("240")
.Add();
col.Field("inActive")
.HeaderText("Active Task")
.Width("110")
.DisplayAsCheckBox(true)
.Add();
col.Field("StartDate")
.HeaderText("Start Date")
.Format("yMd")
.TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right)
.Width("120")
.Add();
col.Field("Duration")
.HeaderText("Duration")
.TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right)
.Width("90")
.Add();
col.Field("Progress")
.HeaderText("Progress")
.TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right)
.Width("120")
.Add();
})
.Render()
<script>
function toolbarClick(args) {
var gantt = document.getElementById("GanttContainer").ej2_instances[0];
if (args.item.id === "GanttContainer_pdfexport") {
gantt.pdfExport();
}
}
</script>public IActionResult Index()
{
ViewBag.DataSource = ganttData();
return View();
}
public static List<GanttDataSource> GanttData()
{
List<GanttDataSource> data = new List<GanttDataSource>();
// Project Planning
GanttDataSource record1 = new GanttDataSource()
{
TaskId = 1,
TaskName = "Project planning",
StartDate = new DateTime(2025, 4, 2),
Duration = 10,
Progress = 40,
SubTasks = new List<GanttDataSource>()
};
record1.SubTasks.Add(new GanttDataSource()
{
TaskId = 2,
TaskName = "Requirements gathering",
StartDate = new DateTime(2025, 4, 2),
Duration = 3,
Progress = 50,
InActive = false
});
record1.SubTasks.Add(new GanttDataSource()
{
TaskId = 3,
TaskName = "Stakeholder interviews",
StartDate = new DateTime(2025, 4, 7),
Duration = 2,
Progress = 30,
InActive = true
});
record1.SubTasks.Add(new GanttDataSource()
{
TaskId = 4,
TaskName = "Plan approval",
StartDate = new DateTime(2025, 4, 9),
Duration = 0,
Progress = 100,
InActive = false
});
// Design Phase
GanttDataSource record2 = new GanttDataSource()
{
TaskId = 5,
TaskName = "Design phase",
StartDate = new DateTime(2025, 4, 10),
Duration = 10,
Progress = 20,
InActive = false,
SubTasks = new List<GanttDataSource>()
};
GanttDataSource uiDesign = new GanttDataSource()
{
TaskId = 6,
TaskName = "UI design",
StartDate = new DateTime(2025, 4, 10),
Duration = 5,
Progress = 50,
InActive = true,
SubTasks = new List<GanttDataSource>()
};
uiDesign.SubTasks.Add(new GanttDataSource()
{
TaskId = 7,
TaskName = "Create wireframes",
StartDate = new DateTime(2025, 4, 3),
Duration = 2,
Progress = 80,
InActive = false
});
uiDesign.SubTasks.Add(new GanttDataSource()
{
TaskId = 8,
TaskName = "Review wireframes",
StartDate = new DateTime(2025, 4, 14),
Duration = 2,
Progress = 25,
InActive = true
});
record2.SubTasks.Add(uiDesign);
record2.SubTasks.Add(new GanttDataSource()
{
TaskId = 9,
TaskName = "Build prototype",
StartDate = new DateTime(2025, 4, 15),
Duration = 4,
Progress = 10,
InActive = false
});
// Development
GanttDataSource record3 = new GanttDataSource()
{
TaskId = 10,
TaskName = "Development",
StartDate = new DateTime(2025, 4, 20),
Duration = 10,
Progress = 30,
InActive = true,
SubTasks = new List<GanttDataSource>()
};
record3.SubTasks.Add(new GanttDataSource()
{
TaskId = 11,
TaskName = "Frontend implementation",
StartDate = new DateTime(2025, 4, 6),
Duration = 5,
Progress = 60,
InActive = false
});
record3.SubTasks.Add(new GanttDataSource()
{
TaskId = 12,
TaskName = "Backend implementation",
StartDate = new DateTime(2025, 4, 20),
Duration = 5,
Progress = 35,
InActive = true
});
// Testing
GanttDataSource record4 = new GanttDataSource()
{
TaskId = 13,
TaskName = "Testing",
StartDate = new DateTime(2025, 4, 1),
Duration = 5,
Progress = 0,
InActive = false,
SubTasks = new List<GanttDataSource>()
};
record4.SubTasks.Add(new GanttDataSource()
{
TaskId = 14,
TaskName = "Functional testing",
StartDate = new DateTime(2025, 4, 1),
Duration = 3,
Progress = 40,
InActive = true
});
record4.SubTasks.Add(new GanttDataSource()
{
TaskId = 15,
TaskName = "Regression testing",
StartDate = new DateTime(2025, 4, 4),
Duration = 2,
Progress = 90,
InActive = false
});
data.Add(record1);
data.Add(record2);
data.Add(record3);
data.Add(record4);
return data;
}
public class GanttDataSource
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public int? Duration { get; set; }
public int Progress { get; set; }
public bool InActive { get; set; }
public List<GanttDataSource> SubTasks { get; set; }
}Updating inactive tasks dynamically
The inactive state of a task can be updated at runtime using the updateRecordByID method. Pass the task ID and the data source field that mapped to inActiveState.
To mark a task inactive:
gantt.updateRecordByID({
TaskID: 2,
Inactive: true
});Multiple tasks can be updated in a single call using the updateInActiveTaskStateByID method. Each entry in the array takes the task id and an isInActive value.
gantt.updateInActiveTaskStateByID([
{ id: 2, isInActive: true },
{ id: 4, isInActive: false }
]);After the update, the Gantt Chart recalculates the affected schedule and redraws the tasks that changed. The state change is recorded as a single action, so can undo it with the undo redo feature and the checkbox returns to its previous value.
Parent task behavior
Inactive task status is propagated throughout the task hierarchy to ensure scheduling consistency.
The following rules apply to parent tasks:
- Marking a parent task as inactive automatically marks all of its descendant tasks as inactive.
- A parent task is automatically rendered as inactive when all of its child tasks are inactive.
- Re-activating a child task also re-activates its parent task, while other inactive sibling tasks remain unchanged.
- Parent taskbars are rendered using the inactive visual style whenever the parent task is considered inactive.
Dependency behavior
Dependency relationships are preserved when tasks become inactive. The links remain in the project data and continue to be validated based on the active or inactive state of the connected tasks.
The scheduling behavior varies depending on the state of the predecessor and successor tasks:
- Inactive predecessor, active successor. An inactive predecessor does not influence the schedule of an active successor.
- Active predecessor, inactive successor. The active predecessor still drives the inactive successor, because the predecessor is part of the active schedule.
- Both tasks inactive. The link is still validated, so an inactive successor follows its inactive predecessor as expect for a chain of paused tasks.
- Both tasks active. Nothing changes. The link behaves exactly as it did before the feature was enabled.
While a task is inactive, its own dates are the ones that count. Dragging, resizing, cell editing, and dialog editing an inactive task change only that task’s own dates. They do not move any other task.
Inactive tasks are also excluded from critical path calculations. Therefore, a paused or inactive task never appears on the critical path, and its end date does not affect the project’s critical reference date.