Is it possible to exclude a day from the specific week?


#1

Team,
I have a configuration settings like below.,
Weekdays = [1,2,3,4,5] {Monday to Friday}
Weekends = [0,6] {Saturday and Sunday}
excludeddays = {4:[1,2,3,5], 3:[2,4,5]} {We have to exclude first, second, third, and 5th week of Thursdays and exclude second, 4th and 5th week of Wednesdays}

And i have used addMarkedTimespan function to achieve weekends, and weekdays like below.,

	    $.each(weekdays, function (key, item) {
			o.scheduler.addMarkedTimespan({
				days: item,
				zones: [0,12*60, 13*60, 24*60]
				invert_zones: false,
				css: "working_time", 
				sections: {
					timeline: ownerId 
				}
			});	
		});       
            $.each(weekends, function (key, item) {
			o.scheduler.addMarkedTimespan({
				days: item,
				zones: "fullday", 
				css: "working_time", 
				sections: {
					timeline: ownerId
				}
			});
		});

Both of the weekdays, weekends are working fine. Is there any possible way to do excluded days ?


#2

Hello @Vijay_kumar ,

Yes, you can do it using the onBeforeViewChange event:
https://docs.dhtmlx.com/scheduler/api__scheduler_onbeforeviewchange_event.html

The thing that you should do, is to define different exclude days for required weeks, and in case if is the new date is a required week - apply new filtering:

var evenWeekConfig;
scheduler.ignore_week = function(date){
  if(evenWeekConfig){
    if (date.getDay() == 0 || date.getDay() == 1 ||  date.getDay() == 2) return true;
  }
  else {
    if (date.getDay() == 3 || date.getDay() == 4 ||  date.getDay() == 5) return true;
  } 
};
scheduler.attachEvent("onBeforeViewChange", function(old_mode,old_date,mode,date){
  if(scheduler.date.getISOWeek(new Date(date))%2 == 0)
    evenWeekConfig = true;
  if(scheduler.date.getISOWeek(new Date(date))%2 != 0)
    evenWeekConfig = false;
  return true;
}); 

Here is an example(filter different days for even/odd weeks):
http://snippet.dhtmlx.com/5/c18965be1