我正在显示一个带有日期槽的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|...
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
是否尝试将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,
...
});
});