JavaScript UI Libraries & Blazor Components Suite – Smart UI Forums Scheduler [Blazor Scheduler]How to add an item to a scheduler datasource from an event

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #103547
    einaradolfsen
    Participant

    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();

    }

    #103553
    admin
    Keymaster

    Hi,

    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 Stoev

    Smart UI Team
    https://www.htmlelements.com/

    #109203
    Lukas Xaver
    Participant

    Hej 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,
    Lukas

    #109205
    ivanpeevski
    Participant

    Hi 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 Peevski

    Smart UI Team
    https://www.htmlelements.com/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.