2012-02-20 123 views
1

我目前正在开发一个包括fullcalendar JQuery插件的项目。 我想通过点击议程周日或议程日期中的日标题来创建一个包含选定日期的所有活动(附加信息)的列表。我通过viewDisplay选项绑定了表格标题的点击事件:FullCalender:将点击事件绑定到表头

viewDisplay: function(view){ 
    $('table.fc-agenda-days thead th').each(function(){ 
     if($(this).html() != " "){ 
      $(this).css('cursor','pointer'); // set cursor 
      $(this).unbind('click'); //unbind previously bound 'click' 
      $(this).click(function(){ 
       // to be continued....  
      }); 
     } 
    }); 
} 

这工作正常......但如何从那里继续?我唯一可以检索的是日期标题(例如“Sun 2/19”)。也许有一个更简单的解决方案?

感谢您的帮助!

回答

2

我通过更改weekView的columnFormat来读取完整日期来解决。在我来说,我的加泰罗尼亚语言环境:

columnFormat: { 
     month: 'ddd', 
     week: 'dddd dd/MM/yyyy', 
     day: 'dddd dd/MM/yyyy' 
    } 

然后在viewDisplay可以解析完整的日期,并导航到agendaDay上点击日期:

viewDisplay: function(view) { 
     // Add onclick to header columns of weekView to navigate to clicked day on dayView 
     $('table.fc-agenda-days thead th').each(function(){ 
      if($(this).html() != " "){ 
       $(this).css('cursor','pointer'); // set cursor 
       $(this).unbind('click'); //unbind previously bound 'click' 
       $(this).click(function(){ 
        var dateStr = $(this).html().substring($(this).html().indexOf(' ')+1); 
        var day = dateStr.substring(0, 2); 
        var month = dateStr.substring(3, 5) - 1; 
        var year = dateStr.substring(6, 10); 
        $('#calendar').fullCalendar('gotoDate', new Date(year, month, day)); 
        $('#calendar').fullCalendar('changeView', 'agendaDay'); 
       }); 
      } 
     }); 
    } 
0

尝试这种解决方法我自己做。 通过在fullcalendar初始化后调用zumaMaker(),可以通过点击day标题使得从agendaWeek导航到agendaDay。

function zumaMaker() { 

var arrayUIDays = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; 
for (var m = 0; m < arrayUIDays.length; m++) { 
    var dim = ".fc-day-header.fc-widget-header.fc-" + arrayUIDays[m]; 
    var dok = $(dim).html(); 
    $(dim).attr("onclick", "zumaMethod('" + dok + "','" + dim + "');"); 
    $(dim).css("cursor", "pointer"); 
    } 
} 

function zumaMethod(doma, diver) { 

    var date = doma.split(" ")[1].split("/"); 
    var day = date[0]; 
    var month = date[1]; 
    var year = date[2]; 
    var off_date = year + "-" + month + "-" + day + "T" + "00:00:00"; 

    $("#pl_tbl").fullCalendar('changeView', 'agendaDay'); 
    $("#pl_tbl").fullCalendar('gotoDate', off_date); 
    $(diver).css("cursor", "pointer"); 
    $(diver).attr("onclick", "zumaMethodRevert();"); 
} 

function zumaMethodRevert() { 
    $("#pl_tbl").fullCalendar('changeView', 'agendaWeek'); 
    zumaMaker(); 
} 

你也可以添加这个CSS来定制悬停时的标题。

.fc-day-header:hover { 
    background-color: orange; 
} 
.fc-day-header { 
    background-color: white; 
}