Set different work hours in Vue Schedule component
11 Jun 202410 minutes to read
By default, the work hours of the Scheduler is highlighted based on the start and end values provided within the workHours
property which remains same for all days. To highlight different work hours range for different days,setWorkHours
method. You can pass date object/ multiple date objects collection as first argument and start and end time need to be added as work hours should be passed as second and third arguments respectively. In the following code example, on button click 11:00 AM to 08:00 PM of 15th and 17th February has been added in work hours.
<template>
<div>
<div id='app'>
<div id='container'>
<tr>
<td>
<div>
<ejs-button id='btn1' v-on:click='onChangeWorkHours'>Change the Work Hours</ejs-button>
</div>
</td>
</tr>
<ejs-schedule ref='scheduleObj' width='100%' height='500px' :eventSettings='eventSettings'
:selectedDate='selectedDate' :workHours='workHours'>
<e-views>
<e-view option='Day'></e-view>
<e-view option='Week'></e-view>
<e-view option='WorkWeek'></e-view>
<e-view option='Month'></e-view>
</e-views>
</ejs-schedule>
</div>
</div>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { extend } from '@syncfusion/ej2-base';
import { scheduleData } from './datasource.js';
import { ButtonComponent as EjsButton } from '@syncfusion/ej2-vue-buttons';
import { ScheduleComponent as EjsSchedule, ViewDirective as EView, ViewsDirective as EViews, Day, Week, WorkWeek, Month } from '@syncfusion/ej2-vue-schedule';
const scheduleObj = ref(null);
const eventSettings = { dataSource: extend([], scheduleData, null, true) };
const workHours = {
highlight: true,
start: '09:00',
end: '11:00'
};
const selectedDate = new Date(2018, 1, 15)
provide('schedule', [Day, Week, WorkWeek, Month]);
const onChangeWorkHours = function () {
let dates = [new Date(2018, 1, 15), new Date(2018, 1, 17)];
scheduleObj.value.setWorkHours(dates, '11:00', '20:00');
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-schedule/styles/material.css';
</style>
<template>
<div>
<div id='app'>
<div id='container'>
<tr>
<td>
<div>
<ejs-button id='btn1' v-on:click='onChangeWorkHours'>Change the Work Hours</ejs-button>
</div>
</td>
</tr>
<ejs-schedule ref='scheduleObj' width='100%' height='500px' :eventSettings='eventSettings'
:selectedDate='selectedDate' :workHours='workHours'>
<e-views>
<e-view option='Day'></e-view>
<e-view option='Week'></e-view>
<e-view option='WorkWeek'></e-view>
<e-view option='Month'></e-view>
</e-views>
</ejs-schedule>
</div>
</div>
</div>
</template>
<script>
import { extend } from '@syncfusion/ej2-base';
import { scheduleData } from './datasource.js';
import { ButtonComponent } from '@syncfusion/ej2-vue-buttons';
import { ScheduleComponent, ViewDirective, ViewsDirective, Day, Week, WorkWeek, Month } from '@syncfusion/ej2-vue-schedule';
export default {
name: "App",
components: {
"ejs-button": ButtonComponent,
"ejs-schedule": ScheduleComponent,
"e-views": ViewsDirective,
"e-view": ViewDirective
},
data() {
return {
eventSettings: { dataSource: extend([], scheduleData, null, true) },
workHours: {
highlight: true,
start: '09:00',
end: '11:00'
},
selectedDate: new Date(2018, 1, 15)
}
},
provide: {
schedule: [Day, Week, WorkWeek, Month]
},
methods: {
onChangeWorkHours: function () {
let dates = [new Date(2018, 1, 15), new Date(2018, 1, 17)];
this.$refs.scheduleObj.setWorkHours(dates, '11:00', '20:00');
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-vue-schedule/styles/material.css';
</style>