[PR #1951] ResourceScheduler - Initial Draft #2991

Open
opened 2026-01-29 18:21:25 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/radzenhq/radzen-blazor/pull/1951

State: closed
Merged: No


Hi all

Further to Scheduler - Resource and/or grouping

Hi @Christine_Chetty,

No, this isn't part of our short term plans. We would gladly accept a pull request implementing that feature though!

this is a draft PR with my effort for implementing the above. It is a draft PR as I know there are at least a few items still to resolve, documentation comments, moving css out of razor files, complete testing, e.t.c., but I wanted to check that what I'm putting forward looks acceptable.

Some notes on implementation

Changes to existing files
The majority of the logic still resides in the Scheduler component. I've tried to do this with minimal change to any existing files.
Reason for changes to existing files are as follows -

SchedulerViewBase.cs
Additional CascadingParameter required in order to attach ResourceScheduler to the View in the same way it does with Scheduler.

RadzenScheduler.razor.cs
Additional signature for SelectView so that an Index can be passed as opposed to an ISchedulerView object. This is because the ResourceScheduler accepts a collection of Views as the ChildContent in the same way as Scheduler does, but each Scheduler component (TResource column) will have it's own Views collection. The actual object wouldn't match, so we select by index instead.

SchedulerSlotEventArgs.cs
Because we are calling from another component, we have to change the scope of the IsDefaultPrevented property to internal.

Navigation methods (OnPrev, OnNext, Today and View selections)
The majority of what the ResourceScheduler does is act as a conduit for the existing Scheduler methods and events, but adding the Resource element to them.

In the case of navigation methods, they all follow the same basic pattern -

        async Task OnPrev()
        {
            var newDate = SelectedView.Prev();

            foreach (var scheduler in Schedulers)
            {
                scheduler.Value.CurrentDate = newDate;
            }
            await InvokeLoadData();
        }

iterating through the Dictionary<TLink, RadzenScheduler<TItem>> Schedulers { get; set; } = new(); that is populated during the render process <RadzenScheduler @ref=@Schedulers[resourceId] and actioning the appropriate existing Scheduler method.

Event Handlers
These are basically extensions of the existing event handlers, but with the TResource added to the args. They are built in the following way using a Dictionary to hold the handler for each Scheduler (example using SlotSelect event)-

        [Parameter]
        public EventCallback<ResourceSchedulerSlotSelectEventArgs<TResource>> SlotSelect { get; set; }


        Dictionary<TLink, Action<SchedulerSlotSelectEventArgs>> OnSlotSelect = [];


        protected override void OnInitialized()
        {
            foreach (var resource in ResourceData)
            {
                TLink id = (TLink)(resource.GetType().GetProperty(ResourceLinkProperty).GetValue(resource));

                OnSlotSelect[id] = async (args) =>
                {
                    var args_resource = new ResourceSchedulerSlotSelectEventArgs<TResource> { Resource = resource, Appointments = args.Appointments, Start = args.Start, End = args.End, IsDefaultPrevented = args.IsDefaultPrevented, View = args.View };

                    await SlotSelect.InvokeAsync(args_resource);
                };
            }
        }

Some of the events have additional code to handle drag drop, in much the same way as the code from the DataGrid to Scheduler drag drop example.

I think that covers most of the bones of the component. I'm sure the source will reveal anything I've missed.

Hope this is of interest

Regards
Paul

**Original Pull Request:** https://github.com/radzenhq/radzen-blazor/pull/1951 **State:** closed **Merged:** No --- Hi all Further to [Scheduler - Resource and/or grouping](https://forum.radzen.com/t/scheduler-resource-and-or-grouping/12761) > Hi @Christine_Chetty, > > No, this isn't part of our short term plans. We would gladly accept a pull request implementing that feature though! > this is a draft PR with my effort for implementing the above. It is a draft PR as I know there are at least a few items still to resolve, documentation comments, moving `css` out of razor files, complete testing, e.t.c., but I wanted to check that what I'm putting forward looks acceptable. _Some notes on implementation_ **Changes to existing files** The majority of the logic still resides in the Scheduler component. I've tried to do this with minimal change to any existing files. Reason for changes to existing files are as follows - _SchedulerViewBase.cs_ Additional `CascadingParameter` required in order to attach `ResourceScheduler` to the `View` in the same way it does with `Scheduler`. _RadzenScheduler.razor.cs_ Additional signature for `SelectView` so that an `Index` can be passed as opposed to an `ISchedulerView` object. This is because the `ResourceScheduler` accepts a collection of `Views` as the `ChildContent` in the same way as `Scheduler` does, but each `Scheduler` component (`TResource` column) will have it's own `Views` collection. The actual object wouldn't match, so we select by index instead. _SchedulerSlotEventArgs.cs_ Because we are calling from another component, we have to change the scope of the `IsDefaultPrevented` property to `internal`. **Navigation methods (OnPrev, OnNext, Today and View selections)** The majority of what the `ResourceScheduler` does is act as a conduit for the existing `Scheduler` methods and events, but adding the `Resource` element to them. In the case of navigation methods, they all follow the same basic pattern - ``` async Task OnPrev() { var newDate = SelectedView.Prev(); foreach (var scheduler in Schedulers) { scheduler.Value.CurrentDate = newDate; } await InvokeLoadData(); } ``` iterating through the `Dictionary<TLink, RadzenScheduler<TItem>> Schedulers { get; set; } = new();` that is populated during the render process `<RadzenScheduler @ref=@Schedulers[resourceId]` and actioning the appropriate existing `Scheduler` method. **Event Handlers** These are basically extensions of the existing event handlers, but with the `TResource` added to the `args`. They are built in the following way using a `Dictionary` to hold the handler for each `Scheduler` (example using `SlotSelect` event)- ``` [Parameter] public EventCallback<ResourceSchedulerSlotSelectEventArgs<TResource>> SlotSelect { get; set; } Dictionary<TLink, Action<SchedulerSlotSelectEventArgs>> OnSlotSelect = []; protected override void OnInitialized() { foreach (var resource in ResourceData) { TLink id = (TLink)(resource.GetType().GetProperty(ResourceLinkProperty).GetValue(resource)); OnSlotSelect[id] = async (args) => { var args_resource = new ResourceSchedulerSlotSelectEventArgs<TResource> { Resource = resource, Appointments = args.Appointments, Start = args.Start, End = args.End, IsDefaultPrevented = args.IsDefaultPrevented, View = args.View }; await SlotSelect.InvokeAsync(args_resource); }; } } ``` Some of the events have additional code to handle drag drop, in much the same way as the code from the `DataGrid` to `Scheduler` drag drop example. I think that covers most of the bones of the component. I'm sure the source will reveal anything I've missed. Hope this is of interest Regards Paul
claunia added the pull-request label 2026-01-29 18:21:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#2991