按月过滤Jquery Fullcalendar

时间:2016-11-29 13:00:34

标签: jquery fullcalendar

我们有什么方法可以按月过滤FullCalendar。这样我们就可以从下拉列表中选择特定月份并加载事件。

此致

1 个答案:

答案 0 :(得分:1)

您可以使用月份生成一个选择,然后使用 gotoDate

演示@ https://jsfiddle.net/L6a5LL5b/

HTML

<div id='caljump'>
    <label for='months'>Jump to</label>
    <select id='months'></select>
</div>
<div id='calendar'></div>

JS

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

    $calendar.fullCalendar({
        viewRender: function() {
            buildMonthList(); // update the jump list when the view changes
        }
    });

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

    buildMonthList(); // set initial jump list on load

    function buildMonthList() {
        $('#months').empty(); // clear jump list
        var month = $calendar.fullCalendar('getDate');
        var initial = month.format('YYYY-MM'); // where are we?
        month.add(-6, 'month'); // 6 months past
        for (var i = 0; i < 13; i++) { // 6 months future
            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'); // current selection
            $months.append(opt);
            month.add(1, 'month');
        }
    }
});