We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Different work hours for each day.

Hi Team,

I need to be set the different work hours for each day.

Following are the day and their work hours and they have stored in State variable name as "workHours" as below.



While set-up work hours with scheduler component with the reference of code in synchfusion.

I'm using "forEach" loop to set workHours.

However in the result, workHours only applied to Sunday, Thursday and Friday...and for the remaining day it applies the default workHours i.e "09:00" to "18:00".

Below is the sample code while set-up work hours in component.

this.scheduleObj.activeView.renderDates.forEach(element => {
    let day = (new Date(element).getDay()) + 1
    this.workHours.forEach(workHour => {
        if (workHour.DayNo === day) {
            //console.log(new Date(element).getDay(),workHour.DayNo,[new Date(element)], workHour.StartTime, workHour.EndTime)
            this.scheduleObj.setWorkHours([new Date(element)],workHour.StartTime, workHour.EndTime)                            
        }
    })
})

Kindly suggest the solution for it.

Regards,
Sinchan.

3 Replies

VD Vinitha Devi Murugan Syncfusion Team December 17, 2019 08:45 AM UTC

Hi Sinchan, 
 
Syncfusion Greetings. 
 
We could reproduce the issue at our end. Before setting custom work hours, we need to reset the work hours as highlighted below to resolve this problem. For your reference we prepared the sample below. 
 

onDataBinding() { 
    if ((this.scheduleObj.activeView.viewClass !== "e-month-view") && (this.scheduleObj.activeView.viewClass !== 'e-agenda-view')) { 
      this.scheduleObj.activeView.renderDates.forEach(element => { 
        let day = (new Date(element).getDay()) + 1 
        this.workHours.forEach(workHour => { 
          if (workHour.DayNo === day) { 
            this.scheduleObj.resetWorkHours([new Date(element)], "00:00", "24:00"); 
            this.scheduleObj.setWorkHours([new Date(element)], workHour.StartTime, workHour.EndTime) 
          } 
        }) 
      }) 
    } 
  } 

 
Kindly try the able sample and let us know if you need further assistance on this. 
                                                                                                           
Regards, 
M.Vinitha devi 



SN Sinchan NIkam December 17, 2019 09:11 AM UTC

It's working.

Many Thanks...


VD Vinitha Devi Murugan Syncfusion Team December 18, 2019 06:22 AM UTC

Hi Sinchan, 
 
Thanks for your update. 
 
You are most welcome 😊 
 
Regards, 
M.Vinitha devi 


Loader.
Live Chat Icon For mobile
Up arrow icon