vkurko / calendar

Full-sized drag & drop JavaScript event calendar with resource & timeline views
https://vkurko.github.io/calendar/
MIT License
969 stars 82 forks source link

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

Closed cipriano200 closed 10 months ago

cipriano200 commented 10 months ago

dayHeaderFormat should have view variable as second parameter?

dayHeaderFormat: function(date, view) {

}
vkurko commented 10 months ago

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

cipriano200 commented 10 months ago

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 10 months ago

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...
        }
    }
};
cipriano200 commented 10 months ago

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