Support programatically changing selected view on RadzenScheduler #755

Closed
opened 2026-01-29 17:42:53 +00:00 by claunia · 6 comments
Owner

Originally created by @justvibesfyi on GitHub (Mar 2, 2023).

Is your feature request related to a problem? Please describe.

There seems to be no way to programatically select RadzenScheduler's view. SelectedIndex only dictates which index is selected on initialize. The user has to click a Scheduler view selection button at the top which calls a private OnChangeView handler.

Describe the solution you'd like

There should be SelectView(ISchedulerView) method on the Scheduler akin to AddView(ISchedulerView)

Describe alternatives you've considered

Tried forcing re-render after changing SelectedIndex and some other workarounds but they were buggy at best.

Originally created by @justvibesfyi on GitHub (Mar 2, 2023). **Is your feature request related to a problem? Please describe.** There seems to be no way to programatically select RadzenScheduler's view. SelectedIndex only dictates which index is selected on initialize. The user has to click a Scheduler view selection button at the top which calls a private `OnChangeView` handler. **Describe the solution you'd like** There should be `SelectView(ISchedulerView)` method on the Scheduler akin to `AddView(ISchedulerView)` **Describe alternatives you've considered** Tried forcing re-render after changing SelectedIndex and some other workarounds but they were buggy at best.
Author
Owner

@akorchev commented on GitHub (Mar 2, 2023):

Setting SelectedIndex is supposed to work: https://forum.radzen.com/t/scheduler-programmatically-set-view-day-week-month/12111. What did you try?

@akorchev commented on GitHub (Mar 2, 2023): Setting SelectedIndex is supposed to work: https://forum.radzen.com/t/scheduler-programmatically-set-view-day-week-month/12111. What did you try?
Author
Owner

@justvibesfyi commented on GitHub (Mar 2, 2023):

I've tried exactly that. It changes it once. Then when you switch back to month view, and click again, nothing happens.

Here are some code snippets. I've just re-tried in in the radzen demo project.

<RadzenScheduler @ref=@scheduler SlotRender=@OnSlotRender style="height: 768px;" TItem="Appointment" Data=@appointments StartProperty="Start" EndProperty="End"
    TextProperty="Text" SelectedIndex="@SelectedIndex"
    ...
@code {
private int SelectedIndex { get; set; } = 2;
...
}
async Task OnSlotSelect(SchedulerSlotSelectEventArgs args)
    {
        SelectedIndex = 0;
        await scheduler.Reload(); 
     }

The Docs on the SelectedView even say "Specifies the initially selected view"

@justvibesfyi commented on GitHub (Mar 2, 2023): I've tried exactly that. It changes it once. Then when you switch back to month view, and click again, nothing happens. Here are some code snippets. I've just re-tried in in the radzen demo project. ```razor <RadzenScheduler @ref=@scheduler SlotRender=@OnSlotRender style="height: 768px;" TItem="Appointment" Data=@appointments StartProperty="Start" EndProperty="End" TextProperty="Text" SelectedIndex="@SelectedIndex" ... ``` ```razor @code { private int SelectedIndex { get; set; } = 2; ... } ```` ```razor async Task OnSlotSelect(SchedulerSlotSelectEventArgs args) { SelectedIndex = 0; await scheduler.Reload(); } ``` The Docs on the SelectedView even say "Specifies the initially selected view"
Author
Owner

@justvibesfyi commented on GitHub (Mar 2, 2023):

Regardless of whether this is a bug or not, I still believe it's beneficial to have #842

@justvibesfyi commented on GitHub (Mar 2, 2023): Regardless of whether this is a bug or not, I still believe it's beneficial to have #842
Author
Owner

@akorchev commented on GitHub (Mar 2, 2023):

Try without calling Reload(). The scheduler should reload if selected index changes (check the linked code in the PR).

We prefer to have only one method of changing views instead of two.

@akorchev commented on GitHub (Mar 2, 2023): Try without calling Reload(). The scheduler should reload if selected index changes (check the linked code in the PR). We prefer to have only one method of changing views instead of two.
Author
Owner

@justvibesfyi commented on GitHub (Mar 2, 2023):

I did. The issue persists. Tried with and without StateHasChanged(); too

I believe the issue here is that the SelectedIndex which is passed as the parameter stays the same. When you manually click on Month, only the scheduler's private selectedIndex changes to 2. When you select the slot again, the SelectedIndex is again set to 0, which is it current value, both inside and outside the Scheduler. Check line 376 in side the RadzenScheduler.razor.cs, maybe you should compare the parameter to selectedView, although that seems hacky.

Once again, dealing with indices which can be changed by simply re-ordering html seems wrong to me and I'd much prefer having a view reference.

@justvibesfyi commented on GitHub (Mar 2, 2023): I did. The issue persists. Tried with and without StateHasChanged(); too I believe the issue here is that the SelectedIndex which is passed as the parameter stays the same. When you manually click on Month, only the scheduler's private `selectedIndex` changes to 2. When you select the slot again, the SelectedIndex is again set to 0, which is it current value, both inside and outside the Scheduler. Check line 376 in side the RadzenScheduler.razor.cs, maybe you should compare the parameter to selectedView, although that seems hacky. Once again, dealing with indices which can be changed by simply re-ordering html seems wrong to me and I'd much prefer having a view reference.
Author
Owner

@akorchev commented on GitHub (Mar 2, 2023):

I just tested it in our online demo and it seems to work as expected. What wouldn't work though is trying to change it a second time. The selectedIndex will stay the same (0) and nothing will change. It would have worked if SelectedIndex supported two-way data-binding @bind-SelectedIndex. Anyway I will accept the PR.

@akorchev commented on GitHub (Mar 2, 2023): I just tested it in our online demo and it seems to work as expected. What wouldn't work though is trying to change it a second time. The selectedIndex will stay the same (0) and nothing will change. It would have worked if SelectedIndex supported two-way data-binding `@bind-SelectedIndex`. Anyway I will accept the PR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#755