OnAppointmentRender not fires in Scheduler YearPlannerView

Hi,
Working with Scheduler i saw that "OnAppointmentRender" event not fires only in YearPlannerView (not even in your tutorial).
Is it intentional or is it a bug?
Thanks

Sorry, I meant in YearView non in YearPlannerView that works correctly

This hasn't been implemented by the author of the pull request which added that view. Feel free to log an issue in our github repository. Or even submit a pull request with the implementation.

1 Like

Hi @valeriano

The YearView doesn't fire this event as it doesn't render appointments as the other views do. While the other views will render each appointment individually (or with a "more..." indicator), the YearView only indicates that appointments exist or not for a particular day.

What was it you trying to achieve?

Regards

Paul

1 Like

I need to show both available days (in green) and unavailable days (in red) for an entire sports year.
Since the YearPlannerView is not adaptive to the screen resolution I would like to do it with YearView.
For the moment I solved it by using the OnSlotRender event

    void OnSlotRender(SchedulerSlotRenderEventArgs args)
    {
        int day = args.Start.Date.DayOfTheWeek();
        if (args.Start.Date < Repo.Parametri.pStagioneDataInizio || args.Start.Date > Repo.Parametri.pStagioneDataFine)
        {
            args.Attributes["style"] = "background: lightyellow; color: lightgray; pointer-events: none;";
        }
        else if (args.Start.Date.DayOfWeek == DayOfWeek.Saturday || args.Start.Date.DayOfWeek == DayOfWeek.Sunday)
        {
            args.Attributes["style"] = "color: maroon;";
        }

        var il = Indispon.Where(i => (i.fsettimana ? args.Start.Date >= i.d_data.Value && args.Start.Date <= i.d_data.Value.AddDays(7) : i.d_data.Value == args.Start.Date) && !i.dispon).ToList();

        if (il.Count() > 0)
        {
            args.Attributes["style"] = "--rz-scheduler-event-background-color: firebrick;";
        }
    }

Regards
Valeriano

1 Like

Hi @valeriano

OnSlotRender IS the correct way to go with this. I used the same using the Planner view for a client.

Is the performance acceptable? I ask because you are running

var il = Indispon.Where(i => (i.fsettimana ? args.Start.Date >= i.d_data.Value && args.Start.Date <= i.d_data.Value.AddDays(7) : i.d_data.Value == args.Start.Date) && !i.dispon).ToList();

for each render. I wondered whether running a linq query and outputting ToList() 365 times would be a performance issue.

Regards

Paul

1 Like

Of course it is certainly better to use "Any", but among the various attempts this code fragment is the one that remained.
I will try to change it as soon as possible
Thank you
Regards
Valeriano

Hi @valeriano

Correction - it's actually 504 times that the OnSlotRender will run (there are 42 slots per month).

Here's the method I used to achieve the same thing. In the OnLoadData event, I gather all the appointments for the year and build a dictionary of dates from these. The OnSlotRender method then looks up the existence of args.Start in this Dictionary to set the style appropriately.

    protected IEnumerable<Booking> bookings;
    Dictionary<DateOnly, bool> hasAppointments = new();

    async Task OnLoadData(SchedulerLoadDataEventArgs args)
    {
        bookings = (await CustomerPortalService.GetBookingsNotMeets()).Where(b => b.Arrive >= args.Start && b.Depart <= args.End);

        hasAppointments = new Dictionary<DateOnly, bool>();

        foreach (Booking b in bookings)
        {
            var startDate = DateOnly.FromDateTime(b.Arrive.Value);
            var endDate = DateOnly.FromDateTime(b.Depart.Value);

            for (DateOnly d = startDate; d <= endDate; d = d.AddDays(1))
            {
                if (!hasAppointments.ContainsKey(d))
                {
                    hasAppointments.Add(d, true);
                }
            }
        }
    }

    void OnSlotRender(SchedulerSlotRenderEventArgs args)
    {
        if (hasAppointments.ContainsKey(DateOnly.FromDateTime(args.Start)))
        {
            args.Attributes["style"] = "background: red;";
        }
        else
        {
            args.Attributes["style"] = "background: green;";
        }
    }

Hope this is of use to you.

Regards

Paul

1 Like

Thanks, it's definitely a more efficient approach
Regards
Valeriano