JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Scheduler › [Blazor Scheduler]How to add an item to a scheduler datasource from an event
Tagged: Blazor; Scheduler
- This topic has 3 replies, 4 voices, and was last updated 1 year ago by ivanpeevski.
-
AuthorPosts
-
August 26, 2022 at 8:11 am #103547einaradolfsenParticipant
How to refresh the scheduler after update the datasource List?
My problem is when the dataSource list is updated the scheduler is not beeing refreshed.
<Button @onclick=”OnAdd”>Add</Button>
private void OnAdd(MouseEventArgs args){
var newEvent = new SchedulerDataSourceWithResource(){ /*set properties here*/};
dataSource.Add(newEvent);StateHasChanged();
}
August 27, 2022 at 8:23 am #103553adminKeymasterHi,
You can use the AddEvent method to add a new Event to the Scheduler.
` private void SchedulerReady(Scheduler scheduler)
{
DateTime today = DateTime.Today;
scheduler.AddEvent(new SchedulerDataSource()
{
Label = “1Google AdWords Strategy”,
DateStart = new DateTime(today.Year, today.Month, today.Day, 9, 0, 0),
DateEnd = new DateTime(today.Year, today.Month, today.Day, 10, 30, 0).AddDays(1),
AllDay = true,
BackgroundColor = “#3F51B5”
});
}`another way is to set the DataSource property of the Scheduler to a new List.
Best regards,
Peter StoevSmart UI Team
https://www.htmlelements.com/November 22, 2023 at 9:30 pm #109203Lukas XaverParticipantHej Peter,
I tried your suggestion today and it did not work.
I changed your event to
new SchedulerDataSource()
{
Id = “1”,
Label = “Google AdWords Strategy NEW”,
DateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0),
DateEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 30, 0),
}when I call AddEvent nothing seems to happen.
I added the event to the DataSource list and nothing happened.The only thing that helped was to call
calendar.Refresh(true);
calendar.Render();after some time through a button click.
When I refresh and render in SchedulerReady(Scheduler scheduler) it doesn’t work too.
Do you have any suggestions what I could try?
Best regards,
LukasNovember 22, 2023 at 11:19 pm #109205ivanpeevskiParticipantHi Lukas,
Adding/Updating items of a List generally doesn’t trigger UI updates. You can notify Blazor by assigning the List to itself. For example:
var newEvent = new SchedulerDataSource()
{
Label = “Review Revenue Projections”,
DateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 45, 0),
DateEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 15, 0, 0),
};
dataSource.Add(newEvent);
// Reassign dataSource to trigger UI update
dataSource = new List<SchedulerDataSource>(dataSource);Best regards,
Ivan PeevskiSmart UI Team
https://www.htmlelements.com/ -
AuthorPosts
- You must be logged in to reply to this topic.