Task Labels in Blazor Gantt Chart Component
22 Nov 20234 minutes to read
The Gantt Chart component maps any data source fields to GanttLabelSettings task labels using the GanttLabelSettings.LeftLabel
, GanttLabelSettings.RightLabel
, and GanttLabelSettings.TaskLabel
properties. You can customize the task labels with templates using GanttLabelSettings.LeftLabelTemplate
, GanttLabelSettings.RightLabelTemplate
and GanttLabelSettings.TaskLabelTemplate
@using Syncfusion.Blazor.Gantt
<SfGantt DataSource="@TaskCollection" Height="450px" Width="900px">
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate"
Duration="Duration" Progress="Progress" ParentID="ParentId">
</GanttTaskFields>
<GanttLabelSettings LeftLabel="TaskId" TValue="TaskData">
<RightLabelTemplate>
<div class="e-right-label-inner-div" style="height:22px;margin-top:7px;">
<span class="e-label">Task Name: @((context as TaskData).TaskName)</span>
</div>
</RightLabelTemplate>
<TaskLabelTemplate>
<div class="e-task-label-inner-div" style="line-height:21px; height:22px;">
<span class="e-label">@((context as TaskData).Progress)%</span>
</div>
</TaskLabelTemplate>
</GanttLabelSettings>
</SfGantt>
@code{
private List<TaskData> TaskCollection { get; set; }
protected override void OnInitialized()
{
this.TaskCollection = GetTaskCollection();
}
public class TaskData
{
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 int? ParentId { get; set; }
}
private static List<TaskData> GetTaskCollection()
{
List<TaskData> Tasks = new List<TaskData>()
{
new TaskData() { TaskId = 1, TaskName = "Project initiation", StartDate = new DateTime(2022, 01, 04), EndDate = new DateTime(2022, 01, 17), },
new TaskData() { TaskId = 2, TaskName = "Identify Site location", StartDate = new DateTime(2022, 01, 04), Duration = "0", Progress = 30, ParentId = 1, },
new TaskData() { TaskId = 3, TaskName = "Perform soil test", StartDate = new DateTime(2022, 01, 04), Duration = "4", Progress = 40, ParentId = 1, },
new TaskData() { TaskId = 4, TaskName = "Soil test approval", StartDate = new DateTime(2022, 01, 04), Duration = "0", Progress = 30, ParentId = 1, },
new TaskData() { TaskId = 5, TaskName = "Project estimation", StartDate = new DateTime(2022, 01, 04), EndDate = new DateTime(2022, 01, 17), },
new TaskData() { TaskId = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2022, 01, 06), Duration = "3", Progress = 30, ParentId = 5, },
new TaskData() { TaskId = 7, TaskName = "List materials", StartDate = new DateTime(2022, 01, 06), Duration = "3", Progress = 40, ParentId = 5, },
new TaskData() { TaskId = 8, TaskName = "Estimation approval", StartDate = new DateTime(2022, 01, 06), Duration = "0", Progress = 30, ParentId = 5, }
};
return Tasks;
}
}
<style>
.e-label {
color: black !important;
}
</style>