Pushkar Adhikari
Pushkar Adhikari

Reputation: 220

how to bind year and month dropdown in fullcalendar (jquery plugin)?

My requirement is to bind these two dropdown with fullcalendar and reflect the changes according. I have already searched lot about binding the custom dropdown to the fullcalendar but not getting success yet!!

So any help is appreciated.

Need these dropdown bind with the fullcalendar

Upvotes: 6

Views: 5161

Answers (1)

$(document).ready(function() {
    var $months = $('#months');
    var $calendar = $('#calendar');

    $calendar.fullCalendar({
        viewRender: function() {
            buildMonthList();
        }
    });

    $('#months').on('change', function() {
        $calendar.fullCalendar('gotoDate', $(this).val());
    });

    buildMonthList();

    function buildMonthList() {
        $('#months').empty();
        var month = $calendar.fullCalendar('getDate');
        var initial = month.format('YYYY-MM');
        month.add(-6, 'month');
        for (var i = 0; i < 13; i++) {
            var opt = document.createElement('option');
            opt.value = month.format('YYYY-MM-01');
            opt.text = month.format('MMM YYYY');
            opt.selected = initial === month.format('YYYY-MM');
            $months.append(opt);
            month.add(1, 'month');
        }
    }
});

Please check this fiddle for month and year dropdown for fullcalendar.

https://jsfiddle.net/L6a5LL5b/

Upvotes: 5

Related Questions