Move appointments but lock the duration

1 Answer 20 Views
ScheduleView
hhgm
Top achievements
Rank 1
Iron
Iron
hhgm asked on 04 Jan 2025, 01:00 PM

I have added a ScheduleView to my project and everything has been working fine as it has been readonly. Now I want to add an edit feature, where I want to allow the user to move the appointments, but the durations needs to be locked.

CustomDragDropBehaviour? or are there a simpler way of doing this?

I also need to apply some validation to the end f the move, and potentially highlight appointments that violate some rules. This I expect to be able to do with some standard validation methodology. Just need to trigger it when move of an appointment has completed.

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 06 Jan 2025, 10:45 AM

Hello Hans-Henrik Møller,

To achieve this requirement, you can implement a custom ScheduleViewDragDropBehavior, which exposes several methods that can be overridden, in order to change the default logic of the control, as well as introduce your logic.

To prevent the change of the appointment's intervals when the user interacts with them, you can override the CanStartResize method and return false. This will allow the user to only drag the appointment, but not change its start and end dates.

To intercept when the appointment is dropped, you can utilize the DragDropCompleted method and introduce your custom validation logic there.

The following code snippets show this suggestion's implementation:

public class CustomDragDropBehavior : ScheduleViewDragDropBehavior
{
    public override bool CanStartResize(DragDropState state)
    {
        return false;
    }

    public override void DragDropCompleted(DragDropState state)
    {
        //Introduce the validation logic here
        base.DragDropCompleted(state);
    }
}

Generally, each of the methods that the ScheduleViewDragDropBehavior class exposes allows you to retrieve the appointment and additional information via the DragDropState parameter.

With this being said, could you give these suggestions a try and let me know how it goes?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

hhgm
Top achievements
Rank 1
Iron
Iron
commented on 07 Jan 2025, 06:36 PM

I will give it a go.. but a little confused. StartResize returns false... you say it will not change the start and end... I guess that is not correct.. it will change the start and end, but preserve the duration of the appintment? Otherwise I am a bit confused..  :-D
Stenly
Telerik team
commented on 08 Jan 2025, 01:40 PM

About the CanStartResize method, it controls whether the user can modify the duration of an appointment by interacting with the handlers. When it is overridden and false is returned, the user will not be able to modify the duration of the appointment by dragging the handlers.

About the modification of the start and end dates when dragging an appointment, indeed you are correct, please excuse me for misleading you with this part. Dragging an appointment will change its start and end dates, however, via the CanStartResize suggestion, the user will not be able to change its duration.

The following GIF shows the result when the CanStartResize method returns false:

The appointment can be dragged (ie change its start and end date), but prevent the change of its duration.

With this being said, I hope the provided information will be of help to you. If any additional assistance is required, please let me know.

hhgm
Top achievements
Rank 1
Iron
Iron
commented on 09 Jan 2025, 05:39 AM

I have a followup question.. I am using the ReadOnlyBehavior to lock everything, and then I have added a ToggleButton to put the dataset into edit mode. 

How can I add and remove the ReadOnlyBehavior code behind. I have tried setting it to null, but that raises some exceptions, indicating I need to do something else or more...

hhgm
Top achievements
Rank 1
Iron
Iron
commented on 10 Jan 2025, 08:09 PM | edited

-- this extra comment is a mistake
Tags
ScheduleView
Asked by
hhgm
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or