Reputation: 11
Is there a way to disable specific dates in Kendo UI's Datepicker component? I am aware that the current API does not support it but does anyone know a work around for this?
Upvotes: 0
Views: 1603
Reputation: 11
Kendo UI team's response to my question:
Datepicker
<kendo-datepicker (open)="onOpen()"></kendo-datepicker>
Function
onOpen(e){
setTimeout(()=>{
document.querySelector('.k-widget.k-calendar.k-calendar-infinite .k-calendar-view .k-content.k-scrollable').addEventListener('scroll', () => {
this.disableDates()
})
this.disableDates()
})
}
public disableDates(){
Array.from(document.querySelectorAll('tbody tr td')).forEach(td => {
if(td.getAttribute('title') == 'Wednesday, July 4, 2018'){
td.classList.add('disabled')
}
})
}
CSS
.disabled{
pointer-events: none;
opacity: 0.5;
}
Plunker: https://plnkr.co/edit/f32f4pKDf4zwVyshZdfJ?p=preview
Upvotes: 0
Reputation: 1884
It is possible to "fake" disabled dates by visualizing and preventing the selection of those dates.
Style the disabled dates by utilizing the kendoCalendarMonthCellTemplate
directive.
e.g. via a disabled
class
<kendo-datepicker>
<ng-template kendoCalendarMonthCellTemplate let-date>
<span [class.disabled]="isDateDisabled(date)">
{{ date.getDate() }}
</span>
</ng-template>
</kendo-datepicker>
In the valueChange
event set the previous selected date if the selected date is disabled.
onValueChange(newDate: Date) {
if (this.isDateDisabled(newDate)) {
this.date = this.lastDate;
} else {
this.date = newDate;
this.lastDate = newDate;
}
}
I've created an example showing this approach in action.
In the provided example I've also added a few tweaks. (e.g.: do not close the calendar if the selected date is disabled)
Upvotes: 1