Completed
Last Updated: 12 Oct 2022 07:26 by ADMIN
Release 3.7.0 (09 Nov 2022)
Rob
Created on: 24 Apr 2020 15:11
Category: Scheduler
Type: Bug Report
2
Toggling AllowUpdate at runtime does not update the scheduler behavior until you toggle a view

<TelerikScheduler AllowCreate="@Editing" AllowDelete="@Editing" AllowUpdate="@Editing" OnDelete="@AppointmentDelete" OnEdit="@AppointmentEdit" OnUpdate="AppointmentUpdate"  Data=…

The above line breaks only with AllowUpdate.

I default Editing false, then toggle it true in the hosting component and do a InvokeAsync(StateHasChanged). 

The result is I can create and delete, but while the appointment hover cursor changes to the hand or arrows and I can see the handlebars to resize the appointment, I'm not able to update the appointment until I switch the SchedulerView. After switching SchedulerView updating works as expected.

2 comments
Rob
Posted on: 24 Apr 2020 16:57

Thanks Marin, 

 Yes, the popup editor does work also, I forgot to mention that.  Thanks for the workaround, I'll implement that.

 Best,

 Rob 

ADMIN
Marin Bratanov
Posted on: 24 Apr 2020 16:06

Hello Rob,

Double clicking to get the popup editor works for me. Does it work for you?

That said, here's a workaround that also seems to work for me (yes, I do toggle the view programmatically):

 

<TelerikButton OnClick="@ToggleEditability">Toggle scheduler editability</TelerikButton>

<TelerikScheduler Data="@Appointments"
                  OnUpdate="@UpdateAppointment"
                  OnCreate="@AddAppointment"
                  OnDelete="@DeleteAppointment"

                  AllowCreate="@IsSchedulerEditable"
                  AllowDelete="@IsSchedulerEditable"
                  AllowUpdate="@IsSchedulerEditable"

                  @bind-Date="@StartDate" Height="600px" @bind-View="@CurrView">
    <SchedulerViews>
        <SchedulerDayView StartTime="@DayStart" />
        <SchedulerWeekView StartTime="@DayStart" />
        <SchedulerMultiDayView StartTime="@DayStart" NumberOfDays="10" />
    </SchedulerViews>
</TelerikScheduler>

@code {
    bool IsSchedulerEditable { get; set; } = false;

    public SchedulerView CurrView { get; set; } = SchedulerView.Week;//used for the workaround

    async Task ToggleEditability()
    {
        IsSchedulerEditable = !IsSchedulerEditable;

        //workaround
        SchedulerView theViewToReturn = CurrView;

        CurrView = theViewToReturn != SchedulerView.Day ? SchedulerView.Day : SchedulerView.Month;
        await InvokeAsync(StateHasChanged);

        await Task.Delay(20);

        CurrView = theViewToReturn;
        //end workaround

        await InvokeAsync(StateHasChanged);
    }


    // Sample CUD operations over the local data
    // In a real case, carry the information over to the actual data source
    void UpdateAppointment(SchedulerUpdateEventArgs args)
    {
        SchedulerAppointment item = (SchedulerAppointment)args.Item;
        var matchingItem = Appointments.FirstOrDefault(a => a.Id == item.Id);
        if (matchingItem != null)
        {
            matchingItem.Title = item.Title;
            matchingItem.Description = item.Description;
            matchingItem.Start = item.Start;
            matchingItem.End = item.End;
            matchingItem.IsAllDay = item.IsAllDay;
            matchingItem.RecurrenceExceptions = item.RecurrenceExceptions;
            matchingItem.RecurrenceRule = item.RecurrenceRule;
        }

        // save to the actual data source here
    }

    void AddAppointment(SchedulerCreateEventArgs args)
    {
        SchedulerAppointment item = args.Item as SchedulerAppointment;
        Appointments.Add(item);

        // save to the actual data source here
    }

    void DeleteAppointment(SchedulerDeleteEventArgs args)
    {
        SchedulerAppointment item = (SchedulerAppointment)args.Item;
        Appointments.Remove(item);

        if (item.RecurrenceId != null)
        {
            // a recurrence exception was deleted, you may want to update
            // the actual data source - an item where theItem.Id == item.RecurrenceId
            // and remove the current exception date from the list of its RecurrenceExceptions
        }

        if (!string.IsNullOrEmpty(item.RecurrenceRule) && item.RecurrenceExceptions?.Count > 0)
        {
            // a recurring appointment was deleted that had exceptions, you may want to
            // delete or update any exceptions from the data source - look for
            // items where theItem.RecurrenceId == item.Id
        }

        // save to the actual data source here
    }

    // sample data and scheduler settings

    public DateTime StartDate { get; set; } = new DateTime(2019, 12, 2);
    public DateTime DayStart { get; set; } = new DateTime(2000, 1, 1, 8, 0, 0); //the time portion is important

    List<SchedulerAppointment> Appointments = new List<SchedulerAppointment>()
{
            new SchedulerAppointment
            {
                Title = "Board meeting",
                Description = "Q4 is coming to a close, review the details.",
                Start = new DateTime(2019, 12, 5, 10, 00, 0),
                End = new DateTime(2019, 12, 5, 11, 30, 0)
            },

            new SchedulerAppointment
            {
                Title = "Vet visit",
                Description = "The cat needs vaccinations and her teeth checked.",
                Start = new DateTime(2019, 12, 2, 11, 30, 0),
                End = new DateTime(2019, 12, 2, 12, 0, 0)
            },

            new SchedulerAppointment
            {
                Title = "Planning meeting",
                Description = "Kick off the new project.",
                Start = new DateTime(2019, 12, 6, 9, 30, 0),
                End = new DateTime(2019, 12, 6, 12, 45, 0)
            },

            new SchedulerAppointment
            {
                Title = "Trip to Hawaii",
                Description = "An unforgettable holiday!",
                IsAllDay = true,
                Start = new DateTime(2019, 11, 27),
                End = new DateTime(2019, 12, 05)
            },

            new SchedulerAppointment
            {
                Title = "Morning run",
                Description = "Some time to clear the head and exercise.",
                Start = new DateTime(2019, 11, 27, 9, 0, 0),
                End = new DateTime(2019, 11, 27, 9, 30, 0),
                RecurrenceRule = "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
            }
    };

    public class SchedulerAppointment
    {
        public Guid Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public bool IsAllDay { get; set; }
        public string RecurrenceRule { get; set; }
        public List<DateTime> RecurrenceExceptions { get; set; }
        public Guid? RecurrenceId { get; set; }

        public SchedulerAppointment()
        {
            Id = Guid.NewGuid();
        }
    }
}

 

 

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.