I have two Kendo Schedulers. In the first one the WorkDayStart and WorkDayEnd should be custom to the day(s) being viewed. They are not static at one single time. If I am viewing one single day, I am sure I could inject some Javascript to find these and update them, then rerender the scheduler. But when viewing a week that would not help. Really they need to be a function. Is this possible?
The second scheduler is grouped by a resource of an Employee. So in this case it is more complicated. I have this one locked down to viewing only a single day view (or other views that don't include slots that may be closed like Agenda). But the columns here are dependent on the employee's availability for the day selected. So again a function is needed.
Alternatively, digging in the kendo.all.js, I see a property called "slotTemplate" but this doesn't seem to be exposed in MVC. Is there a workaround using this?
[EDIT]: I finally found the SlotTemplate as part of the views in MVC. Will play around here and possibly I can solve this on my own.
[EDIT 2]: I did get SlotTemplate working, but the real solution is to fix the WorkDayStart and WorkDayEnd. Let's say this is a program for a store. Bob logs in. Bob sees his own schedule on one tab, and the store schedule on another tab. Bob works different hours per day. The store is open different hours per day. It's not always the same. When viewing a week we need to be expanded to the most open day. When viewing a single day we should match that day.
Here's a SlotTemplate tagged in CSHTML:
views.DayView(v => v.Selected(true)).SlotTemplateId("shopSlotTemplate");
<script id="mySlotTemplate" type="text/x-kendo-template">
#= getSlotTemplate(data, @loggedInEmployeeId) #
</script>
<script id="shopSlotTemplate" type="text/x-kendo-template">
#= getSlotTemplate(data) #
</script>
<script id="acSlotTemplate" type="text/x-kendo-template">
#= getSlotTemplate(data, 0) #
</script>
function getSlotTemplate(data, employeeId) {
// Get employee ID if not passed in. If still not found then this scheduler is not grouped this way.
if (employeeId === undefined) {
employeeId = data.resources().EmployeeId;
}
let isClosed = isShopClosed(shopSchedule.Shop, data.date);
if ((!isClosed) && (employeeId > 0) && (shopSchedule["Employee" + employeeId] !== undefined)) {
isClosed = isShopClosed(shopSchedule["Employee" + employeeId], data.date);
}
return "<div class=\"" + (isClosed ? "k-nonwork-hour" : "") + "\"> </div>";
}
This required new CSS since the TD element has margins.
div.k-scheduler-content > table > tbody > tr > td > div {
margin: -4px -0.5em;
height: calc(100% + 8px);
width: calc(100% + 1em);
}
The end result is that the grid for the scheduler appears how I want it.
But working hours are still inaccurate. They are based on a single date and don't change as I move between days.
Hello Paul,
If I understand correctly, you are trying to change dynamically the WorkDayStart and WorkDayEnd properties based on the selected date, view, and the current user information that you get from a JSON.
If so, what I can recommend you is to hook up forthe Navigate event of the Scheduler, and by using its setOptions method you can change the WorkDayStart and WorkDayEnd properties in a different way based on the result from the JSON, the date, and the current view.
Here is an example: https://netcorerepl.telerik.com/mGaXwCPQ15optq8q11
As you can see when navigating to the next day, the "WorkDayStart" is different. Also, you can get the View and the Date through the event object, which might be helpful in defining the condition.
I hope this helps.