Disabling Different Ranges of Dates in Kendo DatePicker
Environment
Product | Progress® Kendo UI for Angular Editor |
Description
How can I disable different date ranges in the Kendo DatePicker component?
Solution
To disable different ranges of dates and limit the date selection, you can set the disabledDates
property to a custom function.
-
Set the
disabledDates
property to a custom function.<kendo-datepicker ... [disabledDates]="disableRanges"></kendo-datepicker>
-
Inside the function, use conditional statements to define the disabled dates. For example, you can limit the date selection to a 30-day time period starting today. To achieve this, you will need to disable all dates before today and after 30 days by using the following logic:
public disableRanges = (date: Date): boolean => { const today = new Date(); const thirtyDaysFromNow = new Date(); thirtyDaysFromNow.setDate(today.getDate() + 30); return date < today || date > thirtyDaysFromNow; };
-
Now, the DatePicker component will disable all dates before today and after 30 days.