This project demonstrates how you can implement an allowed dates parameter to disable dates
that are not included in your AllowedDates list.
Assume you have a calendar in which you want to disable only a small list of dates, you can achieve that using the clendars DisabledDates parameter, you can read more about it here.
However, what if what you are trying to achieve is the opposite, you have a small list of allowed dates and you wish to disable the dates that are not included in your list.
As shown in Index.razor you have to call DisableDates(DateTime) function and pass it a date that is currently visible in your calendar.
This will detect what month(s) are currently displayed by your calendar and add the displayed days to the DisabledDates list iff they are not available in your AllowedDates list.
What happens if the user changes the current view?
- Using the
DateChangedHandlerwe call theDisableDates(DateTime)function to clear the oldDisabledDateslist and create a new list that contains the disabled days to the navigated view.
The project contains the following methods:
protected override void OnInitialized(): Initializes the current viewvoid DateChangedHandler(DateTime): Is called when the user changes the current viewvoid DisableDates(DateTime): Is called to refreshDisabledDateslist accordingly.IEnumerable<DateTime> GetDisabledDates(DateTime): Gets the date range that are currently displayed by the view excep the dates already available in theAllowedDateslist.
This contribution was made by Hüssam Elvani.