Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 569
Pushkar Adhikari Avatar asked Apr 19 '17 11:04

Pushkar Adhikari


1 Answers

$(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/

like image 170
charulatha krishnamoorthy Avatar answered Sep 23 '22 11:09

charulatha krishnamoorthy