TimelineYear视图中的周数

时间:2016-11-18 10:46:50

标签: fullcalendar fullcalendar-scheduler

我正在显示一个timelineYear视图,其中包含日期位置,其中包含日期和日期的行。

|                         January 2017                         |
|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|...

是否可以为周数显示一行?

|                          January 2017                        |
|       Week 1       |       Week 2       |      Week 3
|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|...

2 个答案:

答案 0 :(得分:0)

您是否尝试将weekNumbers参数设置为true?

$(function() { // document ready

    $('#calendar').fullCalendar({
        now: '2016-09-07',
        editable: true,
        aspectRatio: 1.8,
        scrollTime: '00:00',
        header: {
            left: 'today prev,next',
            center: 'title',
            right: 'timelineDay,timelineTenDay,timelineMonth,timelineYear'
        },
        defaultView: 'timelineDay',
        weekNumbers: true,
        ...
    });

});

最好的问候!
Krzysztof

答案 1 :(得分:0)

weekNumbers选项似乎在timelineYears视图中没有任何效果。我找到了一种方法来使用以下JS添加周数:

var headerRows = $(".fc-head .fc-time-area table tr");
if (headerRows.length == 2) {
    var monthRow = headerRows[0];
    var dayRow = headerRows[1];  

    $.ajax({
       url: '@Url.Action("GetYearWeeks")',
       type: "POST",
       async: true,
       cache: false,
       dataType: "json",
       success: function (response) {

          var cells = $(dayRow).find("th")

          //ADD WEEK ROW             
          var weekRow = $("<tr class='fc-week-header'></tr>")
          $(dayRow).before(weekRow);

          //ADD WEEK CELLS
          var lastWeek = null
          var currentCell = null

          for (var i = 0; i < cells.length; i++) {
            var cellDate = new Date($(cells[i]).data("date"))
            var cellWeek = 1

            for (var y = 0; y < response.length; y++) {
                var startDate = new Date(parseInt(response[y].Start_Date.substr(6)))
                var endDate = new Date(parseInt(response[y].End_Date.substr(6)))
                startDate.setHours(0, 0, 0, 0)
                endDate.setHours(0, 0, 0, 0)

                if (startDate <= cellDate && endDate >= cellDate) {
                    var timeDiff = Math.abs(startDate.getTime() - cellDate.getTime());
                    var diffDays = timeDiff / (1000 * 3600 * 24);                       
                    cellWeek = Math.floor(diffDays / 7) + 1
                    break;
                }
            }

            if (lastWeek != cellWeek) {
                lastWeek = cellWeek
                currentCell = $("<th>" + cellWeek + "</th>")
                currentCell.data("date", cellDate)
                weekRow.append(currentCell)
            }
            else {
                var colSpan = currentCell.attr('colspan')
                if (colSpan == null) {
                    colSpan = 1
                }                   
                colSpan++;

                currentCell.text("Week " + cellWeek)                    
                currentCell.attr('colspan', colSpan)
            }
        }                    

    },
    error: function (jqXHR, textStatus, errorThrown) {
        ShowErrorMessage("Error", errorThrown)
    }
});

Web方法GetYearWeeks返回具有以下属性的对象数组(VB.NET MVC):

Public Class YearWeeks
    Public Property Year As Integer
    Public Property Weeks_In_Year As Integer
    Public Property Start_Date As DateTime
    Public Property End_Date As DateTime     
End Class