vkurko/calendar

Is it possible to get current view inside dayHeaderFormat in v2?

cipriano200 opened this issue · 4 comments

dayHeaderFormat should have view variable as second parameter?

dayHeaderFormat: function(date, view) {

}
vkurko commented

What about getOption('view') or getView() methods?

I tried this:

				dayHeaderFormat: function(date) {
					console.log( calendar.getview() );
				}

But is not working: Uncaught TypeError: Cannot read properties of undefined (reading 'getview')

vkurko commented

Indeed, the calendar is not yet defined at the time of the first call to the function. But you can add an if and you know which view is initially active:

let calendar;
calendar = new EventCalendar(document.getElementById('ec'), {
    view: 'timeGridWeek',
    dayHeaderFormat: function(date) {
        if (!calendar || calendar.getView().type == 'timeGridWeek') {
            // timeGridWeek
        } else if (calendar.getView().type == 'timeGridDay') {
            // timeGridDay
        } else {
            // and so on...
        }
    }
};

Works! Thank your for the help.
I have replaced FullCalendar with your library.