2012-02-20 25 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; 
} 
相關問題