Having trouble getting help?
Contact Support
Contact Support
Set clear button in calendar in Angular Calendar component
5 Apr 20253 minutes to read
The following steps illustrate how to configure clear
button in Calendar UI.
-
On
created
event of Calendar add the required elements to have clear button. Here we have used div with Essential® JS 2 Button component. -
Use the
e-footer
class to the div tag to act as the footer. -
Use button to clear the selected date from the calendar.
-
Bind the required event handler to the button tag to clear the value.
Below is the code example.
import { NgModule } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { BrowserModule } from '@angular/platform-browser'
import { CalendarModule } from '@syncfusion/ej2-angular-calendars'
import { Component, ViewChild } from '@angular/core';
import { CalendarComponent } from '@syncfusion/ej2-angular-calendars';
@Component({
imports: [
CalendarModule,
FormsModule
],
standalone: true,
selector: 'app-root',
styleUrls: ['./style.css'],
template: `
<!-- Bind created event to add the clear button --->
<ejs-calendar #ejCalendar (created)='onCreate()'></ejs-calendar>
`
})
export class AppComponent {
@ViewChild('ejCalendar') ejCalendar?: CalendarComponent;
onCreate() {
let clearBtn: HTMLElement = document.createElement('button');
let footerElement: HTMLElement = document.getElementsByClassName('e-footer-container')[0] as HTMLElement;
//creates the custom element for clear button
clearBtn.className = 'e-btn e-clear e-flat';
clearBtn.textContent = 'Clear';
footerElement.prepend(clearBtn);
(this.ejCalendar as CalendarComponent ).element.appendChild(footerElement);
let proxy = this;
// custom click handler to update the value property with null values.
(document.querySelector('.e-footer-container .e-clear') as Element ).addEventListener('click', function() {
(proxy.ejCalendar as CalendarComponent ).value = null as any;
})
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));