@using Syncfusion.Blazor.Gantt
@using Syncfusion.Blazor.Data
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Popups
@using System.Collections.ObjectModel;
@page "/Foo"
<button @onclick="Add">Add</button><span>@TaskCollection?.Count</span>
<div class="col-lg-12 control-section">
<div class="content-wrapper">
<div class="row">
<SfGantt @ref="Gantt" DataSource="@TaskCollection" Toolbar="toolbar" Height="450px" Width="100%" HighlightWeekends="true"
ProjectStartDate="@ProjectStart" ProjectEndDate="@ProjectEnd">
<GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Progress="Progress"
Dependency="Predecessor" ParentID="ParentId"></GanttTaskFields>
<GanttEditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></GanttEditSettings>
<GanttLabelSettings LeftLabel="TaskName" TValue="TaskData"> </GanttLabelSettings>
<GanttSplitterSettings Position="30%"> </GanttSplitterSettings>
</SfGantt>
</div>
</div>
</div>
@code{
public DateTime ProjectStart = new DateTime(2019, 3, 24);
public DateTime ProjectEnd = new DateTime(2019, 7, 6);
public ObservableCollection<TaskData> TaskCollection { get; set; }
List<string> toolbar = new List<string>()
{ "Add", "Cancel", "CollapseAll", "Delete", "Edit", "ExpandAll", "NextTimeSpan", "PrevTimeSpan", "Search", "Update", "Indent", "Outdent" };
public SfGantt<TaskData> Gantt { get; set; }
async Task Add()
{
var taskData = new TaskData()
{
TaskId = TaskCollection.Count + 1,
TaskName = "Added:" + TaskCollection.Count + 1,
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 08),
Duration = "5days"
};
TaskCollection.Add(taskData);
//await Gantt.AddRecord(taskData);
await Gantt.Refresh();
}
protected override void OnInitialized()
{
this.TaskCollection = new ObservableCollection<TaskData>()
{
new TaskData() {
TaskId = 1,
TaskName = "Product concept ",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 08),
Duration = "5days"
},
new TaskData() {
TaskId = 2,
TaskName = "Defining the product usage",
StartDate = new DateTime(2019, 04, 02),
EndDate = new DateTime(2019, 04, 08),
Duration = "3",
Progress = 30,
ParentId = 1,
BaselineStartDate = new DateTime(2019, 04, 02),
BaselineEndDate = new DateTime(2019, 04, 02),
}
};
}
public class TaskData
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public DateTime? BaselineStartDate { get; set; }
public DateTime? BaselineEndDate { get; set; }
public string Duration { get; set; }
public int Progress { get; set; }
public string Predecessor { get; set; }
public object ResourceId { get; set; }
public string Notes { get; set; }
public string TaskType { get; set; }
public int? ParentId { get; set; }
}
}