Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
718 views
in Technique[技术] by (71.8m points)

javascript - Jquery FullCalendar 2 week view Next prev buttons

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...