开发者

Display 2 weeks in jQuery FullCalendar

开发者 https://www.devze.com 2023-03-14 02:36 出处:网络
Been looking around for a way to display only the current week and the next week in the month view for FullCalendar. So far it looks like it was suggested as a feature for an upcoming version, but in

Been looking around for a way to display only the current week and the next week in the month view for FullCalendar. So far it looks like it was suggested as a feature for an upcoming version, but in the meantime, has anyone been able to hack it in?

UPDATE

Thanks to Doomsday's suggestion, I was able to create a custom view that shows 2 weeks, starting on the current week. You are changing the visible start date to today's date and changing the row count to 2.

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

// exports
t.render = render;


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



function render(date, delta) {
    if (delta) {
        addMonths(date, delta);
        date.setDate(1);
    }
    var start = cloneDate(date, true);
    start.setDate(1);
    var end = addMonths(cloneDate(start), 1);

    //var visStart = cloneDate(start);
    var visStart = date;

    var visEnd = cloneDate(end);
    var firstDay = opt('firstDay');
    var nwe = opt('weekends') ? 0 : 1;
    if (nwe) {
        skipWeekend(visStart);
        skipWeekend(visEnd, -1, true);
    }

    addDays(visStart, -((visStart.getDay() - Math.max(firstDay, nwe) + 7) % 7));
    addDays(visEnd, (7 - visEnd.getDay() + Math.max(firstDay, nwe)) % 7);
    var rowCnt = Math.round((visEnd - visStart) / (DAY_MS * 7));

    if (opt('weekMode') == 'fixed') {
        addDays(visEnd, (6 - rowCnt) * 7);
        //rowCnt = 6;
        rowCnt = 2;
    }
    t.title = formatDate(start, opt('titleFormat'));
    t.start = start;
    t.end = end;
    t.visStart =开发者_JAVA技巧 visStart;
    t.visEnd = visEnd;
    renderBasic(6, rowCnt, nwe ? 5 : 7, true);
}
}


The best solution is it to implement your custom view.

Put in a new JS your own defined view :

$.fullCalendar.views.twoweeks = TwoWeeksView;
function TwoWeeksView(element, calendar) {
    // copy code from fullcalendar.js line 1960
}


The proper answer for fullCalendar 2 is to modify the basicWeek view as explained in the documentation:

    $('#calendar').fullCalendar({
        views: {
            basicWeek: {
                type: 'basic',
                duration: {weeks: 2},
                rows: 2
            }
        }
    }

There. Simple :)


please see here for further information on this fullcalendar custom view

Jquery FullCalendar 2 week view Next prev buttons


Answer will be to display two calendars, one with the current week, and another with the week after.

I suggest you to hack what I've done on this fiddle: http://jsfiddle.net/Doomsday/M3YP3/1/


The latest version now makes it even easier (v2.2.6)

you can also checkout this git where there is a custom twoweek view, that moves 1 week (or whatever option it set to) at a time with the next/prev buttons.

https://github.com/marc-gist/fullcalendar

edit: the gist seems to no longer work with other version of fullcalendar; but look at the docs for an easy week view setup via option values.

0

精彩评论

暂无评论...
验证码 换一张
取 消