Jquery FullCalendar 2 week view Next prev buttons

依然范特西╮ 提交于 2019-11-28 06:16:34

问题


I have implemented the 2 week view outlined here and I was wondering if someone can tell me how/where to change the prev/next buttons to move the calendar only 2 weeks instead of to the next month? Not sure where to update the fullcalendar.js.


回答1:


Figured it out. The problem was that the solution i used was based off the month view when it probably should have been based off of the week view.

first, make sure all the information for the view is listed in the defualts

// time formats
titleFormat: {
    month: 'MMMM yyyy',
    twoweek: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}",
    week: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}",
    day: 'dddd, MMM d, yyyy'
},
columnFormat: {
    month: 'ddd',
    twoweek: 'ddd',
    week: 'ddd M/d',
    day: 'dddd M/d'
},

.

buttonText: {
    prev: ' ◄ ',
    next: ' ► ',
    prevYear: ' << ',
    nextYear: ' >> ',
    today: 'today',
    month: 'month',
    twoweek: '2 week',
    week: 'week',
    day: 'day',
    resourceDay: 'designers'
},

and here is my code for the 2 week view

fcViews.twoweek = TwoWeeksView;

function TwoWeeksView(element, calendar) {
var t = this;

// exports
t.render = render;


// imports
BasicView.call(t, element, calendar, 'twoweek');
var opt = t.opt;
var renderBasic = t.renderBasic;
var formatDates = calendar.formatDates;



function render(date, delta) {
    if (delta) {
        addDays(date, delta*7);
    }
    var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7));
    var end = addDays(cloneDate(start), 7*2);
    var visStart = cloneDate(start);
    var visEnd = cloneDate(end);
    var weekends = opt('weekends');
    if (!weekends) {
        skipWeekend(visStart);
        skipWeekend(visEnd, -1, true);
    }

    t.title = formatDates(
        visStart, 
        addDays(cloneDate(visEnd), -1), 
        opt('titleFormat')
    );
    t.start = start;
    t.end = end;
    t.visStart = visStart;
    t.visEnd = visEnd;
    renderBasic(2, 2, weekends ? 7 : 5, true);
}

}

the key difference here is the last line: renderBasic(2,2,weekends ? 7 : 5, true);

if you dont update the information about the view in defaults, a parameter in formatdates is undefined and there are issues. There are some differences between the week view and the month view that make basing the two week view of the week view instead better. It becomes somewhat of a mix between the two. Hope this helps anyone who is looking for the full 2 week view fix.

call like this:

 $('#calendar').fullCalendar({
        header: {
            left:'prev, next',
            center: 'title',
            right: 'twoweek'
        },
        defaultView: 'twoweek',
        weekMode:'fixed'
  });


来源:https://stackoverflow.com/questions/9708621/jquery-fullcalendar-2-week-view-next-prev-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!