Want to restrict date ranges in FullCalendar? You can use the validRange
property with the following format:
{
start: '2017-05-01',
end: '2017-06-01'
}
To display dates in a specific format like yyyy-MM-dd
, you can utilize the toLocaleDateString()
function with locale set to fr-CA
. Here's an example:
Template
<full-calendar
#calendar
defaultView="dayGridMonth"
[header]="{
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
}"
eventLimit="true"
[validRange]="validRange"
[plugins]="calendarPlugins"
[weekends]="calendarWeekends"
[events]="calendarEvents"
(dateClick)="handleDateClick($event)"
(eventClick)="eventClicked($event)"
></full-calendar>
Controller
export class AppComponent implements OnInit {
validRange = { start: '', end: '' };
.
.
ngOnInit() {
let startDate = new Date();
startDate.setMonth(startDate.getMonth() - 2); // <-- adjust number of months here
this.validRange.start = startDate.toLocaleDateString("fr-CA");
}
}
Check out a working example on Stackblitz