Fullcalendar - event on prev/next click and get value
Each time you change to another month view with prev/next button, a viewRender event is triggered, so you can add to your calendar config a callback to that event. The view parameter has moment dates to first day and last day rendered(start/end, usually they are from previous/next month), and first and last day of current view (intervalStart/intervalEnd, where you can get current month) .
Also, you can got the current date with .fullCalendar('getDate'):
[...]
viewRender: function(view, element) {
console.log(view.start,view.end, view.intervalStart, view.intervalEnd);
console.log($('#calendar').fullCalendar('getDate'));
}
[...]
Documentation: viewRender, getDate.
user2814794
Updated on June 04, 2022Comments
-
user2814794 about 2 years
How would it be possible to call a function by clicking on the prev/next button in monthly view and how to access the value (for example: 2016-04) in that function? I would like to manipulate the URL with the current monthly view by clicking next/prev button.
Thanks
-
Sreekanth Karini about 7 yearsIf viewRender is used, dayRender is not getting called for the first time calendar load. it will become a problem if i use some validations( showing day colors) in dayRender callback
-
Ramon-san about 7 yearsI am not using currently fullCalendar and I can not test it, but you can try to do same validations also in viewRender event for first time, and leave it in dayRender for following renders.