vkurko / calendar

Full-sized drag & drop JavaScript event calendar with resource & timeline views

Home Page:https://vkurko.github.io/calendar/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

cipriano200 opened this issue · comments

dayHeaderFormat should have view variable as second parameter?

dayHeaderFormat: function(date, view) {

}

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')

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.