This is a migrated thread and some comments may be shown as answers.

Working hours of multiple resources (horizontal grouping)

4 Answers 292 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Mor
Top achievements
Rank 1
Mor asked on 27 Mar 2015, 02:03 PM
Hi Telerik.

I am trying to accomplish a scheduler with horizontal grouping of several resources, say mechanics.
So, I have a day view scheduler with a variable number of mechanics as resources on top, comparable to selecting the day view in this demo. Now, I have included the following code:
@(Html.Kendo().Scheduler<VisitViewModel>()
    .Name("scheduler")
    .Date(DateTime.Now)
    .StartTime(7, 0, 0)
    .EndTime(18, 0, 0)
    .Timezone("Etc/UTC")
    .AllDaySlot(false)
    .Views(views => {
        views.DayView(view => view.Selected(true)
            .WorkDayStart(8, 0, 0)
            .WorkDayEnd(17, 0, 0)
            .SelectedDateFormat("{0:dddd d/M/yyyy}"));
    })

.Resources(resource => resource
        .Add(m => m.MechanicId)
        .Title("Mechanic")
        .Name("mechanic")
        .Multiple(false)
        .DataTextField("Text")
        .DataValueField("Value")
        .BindTo(GetMechanics().Select(v => new { Text = String.Format("{0} {1}", v.FirstName, v.LastName), Value = v.Id }).ToArray()))

However, using the above code all mechanics obviously have exactly the same working hours, that is, from 8:00 to 17:00.
Imagine that I have two mechanics, say A and B, and that mechanic A usually works from 8:00 to 17:00 and mechanic B from 9:00 to 18:00.

How can I easily achieve this as the number of mechanics is variable and a mechanic's working hours is extracted from the database for a specific date?
What I would like to accomplish is to add the css class k-nonwork-hour to a resource's (mechanic) unavailable hours. I have an idea of how to obtain the desired result with javascript, but this approach is quite extensive and its code is complex to write and maintain. I wonder whether there's an easier way to achieve this.

I have already resolved this server-side so that you cannot drag and drop an event into a mechanic's unavailable hours, but I would like to show this unavailability visually in the scheduler itself as well.

I am looking forward to hearing from you soon. Thanks in advance!

Kind regards,
Mor

4 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 31 Mar 2015, 07:01 AM
Hello Mor,

Currently the Scheduler doesn't support different working hours for each resource, however you can accomplish this using custom solution. For example you can use the "DataBound" event of the Scheduler to iterate over the slots in current view ("content") and pass each of them to the "slotByElement" method which will return the current underlying slot (it contains the element, start date, end date and resources) that can be used to color the cells correctly.  

Regards,
Vladimir Iliev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mor
Top achievements
Rank 1
answered on 31 Mar 2015, 07:44 AM
Hi Vladimir,

Thanks for the reply. I have noticed that, when iterating over the slots, the resource is indicated by groupIndex. However, this results in {0,n-1} for n resources whereas I would like to be able to obtain the resource id itself, e.g.: where groupIndex is 0, the resource id is 3, where groupIndex is 1, the resource id is 8. Is there a way to obtain these ids?

I have a grid on the left and a scheduler on the right, and I have to drag events from the grid and drop them in the scheduler and events should be bound to a mechanic (which is represented as resource on top of the scheduler). So that whenever I drop an event onto the scheduler, the corresponding action in the controller knows which mechanic (which resource) is attached a new event.

I am looking forward to hearing from you. Thanks!

Kind regards,
Mor
0
Accepted
Vladimir Iliev
Telerik team
answered on 01 Apr 2015, 10:24 AM
Hello Mor,

For your convenience I created small example which shows how to get the current slot corresponding resource values based on the groupIndex which you can use to achieve the desired behavior (check the "dataBound" event):

Regards,
Vladimir Iliev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mor
Top achievements
Rank 1
answered on 01 Apr 2015, 01:28 PM
Hi Vladimir,

Thanks for the reply. I now know how to accomplish it. If I face any problems while implementing it, I'll post my questions in this same thread.

Kind regards,
Mor
Tags
Scheduler
Asked by
Mor
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Mor
Top achievements
Rank 1
Share this question
or