Customization

The Calendar enables the user to render custom components instead of the default ones and, in this way, to customize most of the child Calendar components which are otherwise inaccessible.

The user can replace the following default Calendar components with custom ones:

Cells inside the View

You can customize or completely replace each individual cell inside the Calendar view with a custom component by passing a cell property to the Calendar. The cell property accepts Vue component, a render function, or a named slot. The custom cell receives relevant information about the state of the cell through the props of the Calendar.

Modifying the Cells

To modify an individual cell inside the Calendar view, use the CalendarCell component from the @progress/kendo-date-dateinputs package. CalendarCell will acquire custom behavior and will modify only some of the cells.

For the CalendarCell component to work properly, pass back all properties.

<div id="vueapp" class="vue-app">
  <div class="example-config">
        <calendar :cell="customCell" />
    </div>
</div>
import { Calendar, CalendarCell } from '@progress/kendo-vue-dateinputs';
Vue.component('calendar', Calendar);

const CustomCalendarCell = {
    name: 'CustomCalendarCell',
    props: CalendarCell.props,
    components: {
        'calendar-cell': CalendarCell
    },
    computed: {
        cellStyle: function(){
            return this.$props.isWeekend ? { opacity: '.7' } : { fontWeight: 'bold' }
        }
    },
    methods: {
        handleClick: function(e){
            this.$emit('click', this.$props.value, e);
        }
    },
    template: `<calendar-cell @click="handleClick" :style="cellStyle">
                <slot/>
            </calendar-cell>`
};

new Vue({
    el: '#vueapp',
    data: function(){
        return {
            customCell: CustomCalendarCell
        };
    }
});

Overriding the Default Properties

The cell property allows you to pass any <td /> element as a CalendarCell. This approach is useful for gaining full control over the cell because the CalendarCell component will render additional elements for the default styling.

For the custom cell to allow date selection, manually pass or handle the onClick event.

<div id="vueapp" class="vue-app">
  <div class="example-config">
        <calendar 
            :cell="customCell" 
            :value="value" 
            @change="changeHandler" />
    </div>
</div>
import { Calendar, CalendarCell } from '@progress/kendo-vue-dateinputs';
Vue.component('calendar', Calendar);

const CustomCalendarCell = {
    name: 'CustomCalendarCell',
    props: CalendarCell.props,
    data: function(){
        return {
            title: "We're closed on the weekends!"
        }
    },
    computed: {
        cellStyle: function(){
            return  {
                cursor: 'pointer',
                opacity: this.$props.isWeekend ? .6 : 1
            };
        },
        cellClass: function(){
           return {
                'k-state-selected': this.$props.isSelected,
                'k-state-focused': this.$props.isFocused
            };
        }
    },
    template: `<td
                @click="clickHandler"
                :class="cellClass"
                :style="cellStyle"
                    >
                <span class="k-link" :title="this.$props.isWeekend && this.$data.title">
                   <slot/>
                </span>
            </td>>`,
    methods: {
        clickHandler: function(e) {
            if (!this.$props.isWeekend) {
                this.$emit('click', this.$props.value, e);
            }
        }
    }
};

new Vue({
    el: '#vueapp',
    data: function(){
        return {
            value: null,
            customCell: CustomCalendarCell
        };
    },
    methods: {
        changeHandler: function(event) {
            const dayOfWeek = event.value.getDay();

            // 0 = Sunday, 6 = Saturday
            if (dayOfWeek !== 0 && dayOfWeek !== 6) {
                this.value = event.value;
            }
        }
    }
});

Other Child Components

Similar to the cell property, the Calendar allows you to modify or override other child element through its weekCell and headerTitle.

Cells inside the Week Column

The CalendarWeekCell component represents the week number. CalendarWeekCell is only visible in the month view of the Calendar and if the weekNumber property is set to true. CalendarWeekCell will receive relevant information about its state through the CalendarWeekCellProps.

Titles of Current Views

The CalendarHeaderTitle component represents the title of the current Calendar view and also functions as a button for changing the current view. CalendarHeaderTitle will receive relevant information about its state through the CalendarHeaderTitleProps

For the CalendarHeaderTitle component to work properly, pass back all properties.

<div id="vueapp" class="vue-app">
  <div class="example-config">
        <calendar :header-title="customHeaderTitle"/>
    </div>
</div>
import { Calendar, CalendarHeaderTitle } from '@progress/kendo-vue-dateinputs';
Vue.component('calendar', Calendar);

const CustomHeaderTitle = {
    name: 'CustomHeaderTitle',
    props: CalendarHeaderTitle.props,
    template: `<CalendarHeaderTitle 
                    :id="this.$props.id"
                    :value="this.$props.value"
                    :view="this.$props.view"
                    @click="clickHandler"
                >
                {{this.$props.view === 0
                    ? this.$props.value.split(' ')[0]
                    : this.$props.value}}
                <code v-if="this.$props.view !== 3">↑</code>
            </CalendarHeaderTitle>`,
    methods: {
        clickHandler: function(e) {
            this.$emit('click', e);
        }
    }
};

new Vue({
    el: '#vueapp',
    data: function(){
        return {
            customHeaderTitle: CustomHeaderTitle
        };
    }
});

In this article