Search results

Customization

Calendar allows you to customize the entire appearance by using the custom CSS and renderDayCell event to customize the each day cell.

This following section demonstrates how to disable, highlights the specific dates in the Calendar.

Disable Weekends

You can disable the weekends of every month in a Calendar by using the renderDayCell event. The isDisabled argument from this event allows you to define whether the date to be disabled or not.

Set isDisabled to true to disable the date value.

The following example demonstrates how to disable weekends of every month.

Source
Preview
app.component.ts
app.module.ts
main.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
         <!-- Bind renderDayCell event to customize and disable the day cell. --->
        <ejs-calendar [value]='dateValue' (renderDayCell)='disabledDate($event)'></ejs-calendar>
        `
})

export class AppComponent {
    public dateValue: Date = new Date();
    constructor() {
    }
    disabledDate(args): void {
        if (args.date.getDay() === 0 || args.date.getDay() === 6) {
            //set 'true' to disable the weekends
            args.isDisabled = true;
        }
    }

}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
//Syncfusion ej2-angular-calendars module
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        CalendarModule //declaration of ej2-angular-calendars module into NgModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Day Cell Format

You can highlight the specific dates by adding the custom CSS or element to the day cell by using renderDayCell.

Below is the list of classes that provides the flexible way to customize the Calendar component.

Class Name Description
e-calendar Applied to Calendar.
e-header Applied to header.
e-title Applied to title.
e-icon-container Applied to previous and next icon container.
e-prev Applied to previous icon.
e-next Applied to next icon.
e-weekend Applied to weekend dates.
e-other-month Applied to other month dates.
e-day Applied to each day cell.
e-selected Applied to selected dates.
e-disabled Applied to disabled dates.

The following example highlights the world health date (7th April every year) and world forest day (21st March every year) in a Calendar by using the custom icon and tooltip.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component, ViewEncapsulation, Inject } from '@angular/core';

@Component({
    selector: 'app-container',
    styleUrls: ['styles.css'],
    template: `
        <!-- To customize day calendar appearance -->
        <!-- Refer the "special,highlight-day" class details in "styles.css"-->
        <ejs-calendar [value]='dateValue' (renderDayCell)='customDates($event)'></ejs-calendar>
        `
})

export class AppComponent {
    public dateValue: Date = new Date('3/7/2017');
    constructor() {
    }
    customDates(args): void {
         let span: HTMLElement;
    //defines the custom HTML element to be added.
    span = document.createElement('span');
    //Use "e-icons" class name to load Essential JS 2 built-in icons.
    span.setAttribute('class', 'e-icons highlight-day');
    if (+args.date.getDate() === 7 && +args.date.getMonth() == 3) {
        //append the span element to day cell.
        args.element.appendChild(span);
        //set the custom tooltip to the special dates.
        args.element.setAttribute('title', 'World health day!');
        //Use "special" class name to highlight the special dates, which you can refer in "styles.css".
        args.element.className = 'special';
    }
    if (+args.date.getDate() === 21 && +args.date.getMonth() == 2) {
        args.element.appendChild(span);
        args.element.className = 'special';
        //set the custom tooltip to the special dates.
        args.element.setAttribute('title', 'World forest day');
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
//Syncfusion ej2-angular-calendars module
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        CalendarModule //declaration of ej2-angular-calendars module into NgModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
/* Example - styles */

#container {
    visibility: hidden;
}

#loader {
    color: #008cff;
    height: 40px;
    width: 30%;
    position: absolute;
    top: 45%;
    left: 45%;
}

#element {
    display: block;
    height: 350px;
}

#wrapper {
    width: 250px;
    margin: 0 auto;
}


/* Custom - styles */

.e-icons.highlight-day {
    /* csslint allow: adjoining-classes*/
    color: red;
}

.e-icons.highlight-day {
    /* csslint allow: adjoining-classes*/
    margin-top: -13px;
    display: block;
    margin-left: 4px;
}

.e-icons.highlight-day,

/* csslint allow: adjoining-classes*/

.e-icons.highlight-day:before {
    /* csslint allow: adjoining-classes*/
    color: rgb(0, 0, 255);
}

.e-icons.highlight-day:before {
    /* csslint allow: adjoining-classes*/
    content: "\e190";
    vertical-align: middle;
    margin-right: 3px;
    font-size: 4px;
    position: relative;
    top: 1px;
    font-weight: normal;
}

.special.e-day.e-ripple-style {
    /* csslint allow: adjoining-classes*/
    font-weight: bold;
    color: red;
}

.e-selected .e-icons.highlight-day:before {
    /* csslint allow: adjoining-classes*/
    color: #fff;
}

@font-face {
    font-family: 'e-icons';
    src: url('../../../calendar/fonts/e-icons-metro.ttf') format('truetype'), url('../../../calendar/fonts/e-icons-metro.woff') format('woff'), url('../../../calendar/fonts/e-icons-metro.eot') format('eot'), url('../../../calendar/fonts/e-icons-metro.svg?#e-icons-metro') format('svg');
    font-weight: normal;
    font-style: normal;
}

Highlight Weekends

You can highlight the weekends of every month in a Calendar by using the renderDayCell event. The following example demonstrates how to highlights the weekends of every month.

Source
Preview
app.component.ts
app.module.ts
main.ts
styles.css
import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    template: `
         <!-- Bind renderDayCell event to customize and highlight the weekend of every month. --->
        <ejs-calendar [value]='dateValue' (renderDayCell)='highlightWeekend($event)'></ejs-calendar>
        `
})

export class AppComponent {
    public dateValue: Date = new Date();
    constructor() {
    }
    highlightWeekend(args): void {
        if (args.date.getDay() === 0 || args.date.getDay() === 6) {
            // To highlight the week end of every month
           args.element.classList.add('e-highlightweekend');
        }
    }

}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
//Syncfusion ej2-angular-calendars module
import { CalendarModule } from '@syncfusion/ej2-angular-calendars';
import { AppComponent } from './app.component';


/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        CalendarModule //declaration of ej2-angular-calendars module into NgModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  top: 45%;
  left: 45%;
}

#element {
    display: block;
    height: 350px;
}

#wrapper {
    width: 250px;
    margin: 0 auto;
}

#date_label {
/* csslint ignore:start */
    display: block;
    width: 248px;
    color: rgba(0, 0, 0, 0.58);
    margin-left: 5px;
/* csslint ignore:end */
}

.e-highlightweekend {
    background-color: #cfe9f3;
}