How do I set the date of a calendar view from another view using Jquery FullCalendar?

半世苍凉 提交于 2019-12-04 15:23:58

Here you go--- Its not that difficult actually. Click on the Cal1 day and the Cal2 Changes!

http://jsfiddle.net/ppumkin/A56LN/


CODE


$('#mycalendar1').fullCalendar(
{
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    dayClick: function( date, allDay, jsEvent, view ) {
        dayClicked(date);
    },
    events: [                         
        {
            title  : 'event2',
            start  : '2011-03-10',
            end    : '2011-07-25'
        }
    ]
}); 


$('#mycalendar2').fullCalendar(
            {
             header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                    },

                defaultView: 'agendaDay',

                events: [                         
                        {
                            title  : 'event2',
                            start  : '2011-03-10',
                            end    : '2011-07-25'
                        }
                    ]
           }); 


function dayClicked(date){
    $('#mycalendar2').fullCalendar( 'gotoDate', date );
}

Clicking the "TODAY" and other buttons..

I got some code like this. but this is not the solution. because it shows the date before the calendar changes. so basically the old date- maybe you can use a time-out? 500ms? or something - because jquery binds before the fullcalendar...

$('.fc-button-today').click(function() { 
     alert($('#mycalendar2').fullCalendar( 'getDate' ));
   //dayClicked($('#mycalendar2').fullCalendar( 'getDate' ))

        });

You might have to use the viewDisplay event. But it gets a bit complicated in there. Here is a document how to use it.

http://arshaw.com/fullcalendar/docs/display/viewDisplay/

Look at DoomsDay answer- nice solution :D


An internal hack for day click and possibly other buttons.

You can open fullcalendar.js and goto line about... 3220 or search for Slot/Day clicking and binding

/* Slot/Day clicking and binding
-----------------------------------------------------------------------*/


function dayBind(cells) {
    cells.click(slotClick)
        .mousedown(daySelectionMousedown);

   //OVER HERE INSERT YOUR CUSTOM CALL!
     setMyOtherCalendar();
}

and in your page somewhere you would havbe a public function of setMyOtherCalendar and it would have this simple code in it.. init mate?

function setMyOtherCalendar(){

  $('#mycalendar2').fullCalendar( 'gotoDate',      $('#mycalendar1').fullCalendar( 'getDate' ) );

};

I agree with ppumkin for dayclick.

BUT it is still possible to alter actions of prev,next,today buttons. I will use this solution for navigating from #mycalendar1 to #mycalendar2:

$("#mycalendar1 .fc-button-prev").click(function() {
  $("#mycalendar2").fullCalendar('prev');
});
$("#mycalendar1 .fc-button-next").click(function() {
  $("#mycalendar2").fullCalendar('next');
});
$("#mycalendar1 .fc-button-today").click(function() {
  $("#mycalendar2").fullCalendar('today');
});

And keeping ppumkin solution for dayClick:

dayClick: function( date, allDay, jsEvent, view ) {
   $('#mycalendar2').fullCalendar( 'gotoDate', date );
},

You should use each keyword if you're using .fullcalendar instead of #mycalendar2 (if you are using more than two calendars).

An example is shown on : http://jsfiddle.net/Doomsday/6P2CR/

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