I think I have a better proposal:
<TelerikScheduler @ref=_telerikScheduler Data="@_appointments" @bind-Date="@StartDate" @bind-View="@CurrView" Height="600px" Width="800px">
<SchedulerViews>
<SchedulerDayView StartTime="@DayStart" WorkDayStart="@WorkDayStart" EndTime="@DayEnd" WorkDayEnd="@WorkDayEnd" />
<SchedulerWeekView StartTime="@DayStart" WorkDayStart="@WorkDayStart" EndTime="@DayEnd" WorkDayEnd="@WorkDayEnd" />
<SchedulerMultiDayView StartTime="@DayStart" WorkDayStart="@WorkDayStart" EndTime="@DayEnd" WorkDayEnd="@WorkDayEnd" NumberOfDays="10" />
</SchedulerViews>
</TelerikScheduler>
@code {
private DateTime StartDate { get; set; } = new DateTime(2019, 11, 29);
private SchedulerView CurrView { get; set; } = SchedulerView.Week;
private DateTime DayStart { get; set; } = new DateTime(2000, 1, 1, 6, 0, 0);
private DateTime WorkDayStart { get; set; } = new DateTime(2000, 1, 1, 9, 0, 0);
private DateTime DayEnd { get; set; } = new DateTime(2000, 1, 1, 23, 0, 0);
private DateTime WorkDayEnd { get; set; } = new DateTime(2000, 1, 1, 17, 0, 0);
private TelerikScheduler<SchedulerAppointment> _telerikScheduler;
protected override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_telerikScheduler.ShowWorkHours = true;
}
return Task.CompletedTask;
}
readonly List<SchedulerAppointment> _appointments = new()
{
new SchedulerAppointment
{
Title = "Vet visit",
Description = "The cat needs vaccinations and her teeth checked.",
Start = new DateTime(2019, 11, 26, 11, 30, 0),
End = new DateTime(2019, 11, 26, 12, 0, 0)
},
new SchedulerAppointment
{
Title = "Planning meeting",
Description = "Kick off the new project.",
Start = new DateTime(2019, 11, 25, 9, 30, 0),
End = new DateTime(2019, 11, 25, 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, 07)
}
};
public class SchedulerAppointment
{
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; }
}
}
I also need this. I want to be able to display all the hours of the day, however I want business hours by default.
It could also be setup by a parameter.
In any case, I have added my vote.
The code shown here doesn't seem to work for me. To get it to work, I had to modify the JavaScript to the following...
var btn = document.querySelector('.k-scheduler-fullday');
This worked fine.
Hi Hoon,
In the example I posted, the "schedulerContainer" class is in the <div> around the scheduler, and is used to make the particular cascade to ensure that we click the button on the scheduler you want. Of course, in a real app you should improve on this logic, it is here as a hint mostly. For other classes from the components rendering, you can use the browser devtools to inspect the HTML, classes, rules and so on: https://www.telerik.com/blogs/improve-your-debugging-skills-with-chrome-devtools.
On where our styles come from - by default they come from static assets which is a framework feature, you can read more about this here which also explains what you need to include and how: https://docs.telerik.com/blazor-ui/getting-started/what-you-need.
As to the error you get - my best guess is that the injected JS Runtime is under a different name or there is a different error that you should debug (maybe the JS code is missing or is parsed too late). If you can't figure it out, please open a support ticket and send us a simple runnable sample of the Telerik problem so we can have a look.
Regards,
Marin Bratanov
Progress Telerik
Hi, Marin
Where can I find the tag class definitions such as .schedulerContainer .k-scheduler-fullday etc.? I looked through the css files under www.root/css but no css style sheets are defined with them. Do I need to import a telerik-specific css stylesheet?
A workaround can be to click the button with JS interop when the page loads:
sample script:
<script>
function clickSchedulerBusinessHoursButton(parentClass) {
var btn = document.querySelector(parentClass + '.k-scheduler-fullday span.k-link');
if (btn) {
btn.click();
}
}
</script>
sample component with a scheduler on it:
@inject IJSRuntime _js
<div class="schedulerContainer">
<TelerikScheduler Data="@Appointments" @bind-Date="@StartDate" @bind-View="@CurrView" Height="600px" Width="800px">
<SchedulerViews>
<SchedulerDayView StartTime="@DayStart" WorkDayStart="@WorkDayStart" EndTime="@DayEnd" WorkDayEnd="@WorkDayEnd" />
<SchedulerWeekView StartTime="@DayStart" WorkDayStart="@WorkDayStart" EndTime="@DayEnd" WorkDayEnd="@WorkDayEnd" />
<SchedulerMultiDayView StartTime="@DayStart" WorkDayStart="@WorkDayStart" EndTime="@DayEnd" WorkDayEnd="@WorkDayEnd" NumberOfDays="10" />
</SchedulerViews>
</TelerikScheduler>
</div>
@code {
public DateTime StartDate { get; set; } = new DateTime(2019, 11, 29);
public SchedulerView CurrView { get; set; } = SchedulerView.Week;
public DateTime DayStart { get; set; } = new DateTime(2000, 1, 1, 6, 0, 0);
public DateTime WorkDayStart { get; set; } = new DateTime(2000, 1, 1, 9, 0, 0);
public DateTime DayEnd { get; set; } = new DateTime(2000, 1, 1, 23, 0, 0);
public DateTime WorkDayEnd { get; set; } = new DateTime(2000, 1, 1, 17, 0, 0);
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await _js.InvokeVoidAsync("clickSchedulerBusinessHoursButton", new[] { ".schedulerContainer " });
}
}
List<SchedulerAppointment> Appointments = new List<SchedulerAppointment>()
{
new SchedulerAppointment
{
Title = "Vet visit",
Description = "The cat needs vaccinations and her teeth checked.",
Start = new DateTime(2019, 11, 26, 11, 30, 0),
End = new DateTime(2019, 11, 26, 12, 0, 0)
},
new SchedulerAppointment
{
Title = "Planning meeting",
Description = "Kick off the new project.",
Start = new DateTime(2019, 11, 25, 9, 30, 0),
End = new DateTime(2019, 11, 25, 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, 07)
}
};
public class SchedulerAppointment
{
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; }
}
}
Regards,
Marin Bratanov
Progress Telerik