Scheduler Unit View by week day not date


#1

I am trying to determine if I can setup a unit view scheduler that I can setup to bind by weekday instead of by date. I am trying to display business hours in the format of the calendar but I don’t want any references to dates. Only days of the week. Monday, Tuesday…
Tables:

create table Day(
    key int primary key,
    label nvarchar(15)
)
create table Hours(
    id int primary key,
    start_time time,
    end_time time,
    day_id int
)

#2

Hello,
do you mean you want to show units view in following way?
screencast.com/t/FMGCnCINbkX

It certainly possible. However, technically scheduler always works with a full dates.
So you’ll to do some workarounds in order to make your data compatible with the scheduler.

  1. Data loading

scheduler can only load events that contain full date, so you’ll need to convert your “day - hours” pairs to a valid dates.
Since the dates will be defined by the day of week, you can hardcode some random year-month-date that will be used as a basis for converting the dates. it won’t affect any other logic.
For example, you can take current week

2014-02-03 - Monday
2014-02-04
2014-02-05
2014-02-06
2014-02-07
2014-02-08
2014-02-09 - Sunday

so, all working hours for Monday will always be loaded as “2014-02-03 Hour:Munites”.
And you’ll have to do reverse convertation for saving the data.

  1. Client side - you can make scheduler to display some hardcoded date range(same as used for the data loading), and display appropriate labels so it would appear as days-of-week calendar.
    You’ll also need to add additional logic for scrolling days in the calendar(back/forward buttons in the header). When the user clicks ‘next’ on Sunday, which is last day of date range, calendar should go to the first day.

Client side code might look like following:

[code]scheduler.createUnitsView({
name:“unit”,…
});

//header text
scheduler.templates.unit_date = scheduler.date.date_to_str("%l");

//same date range as on server-side
var min_date = new Date(2014,1,3),
max_date = new Date(2014,1,9);

//ciclycal scroll
scheduler.attachEvent(“onBeforeViewChange”, function(old_mode,old_date,mode,date){
if(date.valueOf() > max_date.valueOf()){
scheduler.setCurrentView(new Date(min_date));
return false;
}else if(date.valueOf() < min_date.valueOf()){
scheduler.setCurrentView(new Date(max_date));
return false;
}
return true;
});

scheduler.init(‘scheduler_here’,min_date,“unit”);[/code]


#3

Thanks for your reply!
After thinking about it a little bit more I was able to use the week view and attach a date during the current week based on which day of the week needed to be displayed.

DateTime curr = DateTime.Now
int diff = DayOfWeek.Sunday - curr.DayOfWeek;
DateTime sunday = curr.AddDays(diff);

private DateTime SetupScheduleDates(int dayID, DateTime startDT, TimeSpan time)
{
     dayID = (dayID == 0) ? 7 : dayID;
     var date = startDT.AddDays((double)dayID)
     return date.Date + time;
}