|
@using Syncfusion.Blazor.Schedule
@using Syncfusion.Blazor.Grids
<div class="row">
<div class="col-lg-6">
<SfGrid @ref="GridRef" DataSource="@Orders" AllowRowDragAndDrop="true" TValue="AppointmentData">
<GridEditSettings AllowDeleting="true"></GridEditSettings>
<GridRowDropSettings TargetID="SchComponent"></GridRowDropSettings>
<GridEvents TValue="AppointmentData" RowDropped="OnRowDrop"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(AppointmentData.Id) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(AppointmentData.StartTime) HeaderText="Start Time" Format="d" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(AppointmentData.EndTime) HeaderText="End Time" Format="d" TextAlign="TextAlign.Right" Width="130"></GridColumn>
</GridColumns>
</SfGrid>
</div>
<div class="col-lg-6">
<div class="SchComponent">
<SfSchedule AllowDragAndDrop="true" ID="Schedueler" @ref="ScheduleObj" TValue="AppointmentData" Height="550px" SelectedDate="@(new DateTime(2020, 1, 9))">
<ScheduleEventSettings DataSource="@DataSource"></ScheduleEventSettings>
</SfSchedule>
</div>
</div>
</div>
<div>
</div>
@code{
SfGrid<AppointmentData> GridRef;
private void OnRowDrop(RowDragEventArgs<AppointmentData> args)
{
ScheduleObj.AddEvent(args.Data[0]);
GridRef.DeleteRecord("Id", args.Data[0]);
}
public static SfSchedule<AppointmentData> ScheduleObj;
public static List<AppointmentData> DataSource = new List<AppointmentData>
{
new AppointmentData { Id = 11, Subject = "Meeting", StartTime = new DateTime(2020, 1, 7, 9, 30, 0) , EndTime = new DateTime(2020, 1, 7, 11, 0, 0),
}
};
public class AppointmentData
{
public int Id { get; set; }
public string Subject { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string RecurrenceRule { get; set; }
public Nullable<int> RecurrenceID { get; set; }
public string RecurrenceException { get; set; }
}
public List<AppointmentData> Orders = new List<AppointmentData>();
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 9).Select(x => new AppointmentData()
{
Id = x,
Subject = (new string[] { "Nancy", "Andrew", "Janet", "Margaret", "Steven" })[new Random().Next(5)],
StartTime = new DateTime(2020, 1, 6, 9, 30, 0),
EndTime = new DateTime(2020, 1, 6, 11, 30, 0),
}).ToList();
}
} |