在完整日历中设置自定义隐藏日期 [英] Setting Custom hiddenDays in Full Calendar
问题描述
我们可以通过设置 hiddenDays 属性来隐藏fullcalendar的特定日子。
我需要隐藏一个月的备用星期六。 / p>
是否有可能?
dayRender
回调函数:
此回调允许您修改属于月份的日单元格,
basicWeek和basicDay视图。请参阅可用视图。
date是给定日期的本地Date对象。
检查显示的是否是一个奇怪的星期六;这样做你可以得到日期的周数,并检查它是否是奇数。
代码:
Date.prototype.getWeekOfMonth = function(exact){
var month = this.getMonth()
,year = this.getFullYear()
, firstWeekday = new Date(year,month,1).getDay()
,lastDateOfMonth = new Date(year,month + 1,0).getDate()
,offsetDate = this.getDate()+ firstWeekday - 1
,index = 1 //开始索引在0或1,您的选择
,weeksInMonth = index + Math.ceil((lastDateOfMonth + firstWeekday - 7)/ 7)
, week = index + Math.floor(offsetDate / 7)
;
if(确切||周<2 +索引)返回周;
回报周=== weeksInMonth?指数+5:周;
};
$ b $ function isOdd(num){return num%2;}
$ b $('#mycalendar')。fullCalendar({
header:{
left:'prev,next today',
center:'title',
right:'month,agendaweek,agendaDay'
},
editable:true,
事件:[{
title:'event1',
start:'2014-01-07'
},{
title:'event2',
start: '2014-01-10',
end:'2013-05-15'
},{
title:'event3',
start:'2014-01-13 12:30:00',
allDay:false //会让时间显示
}],
dayRender:function(date,cell){
if(date.getDay ()== 6&& isOdd(date.getWeekOfMonth())){
$(cell).addClass('fc-disabled');
}
}
});
演示: http://jsfiddle.net/IrvinDominin/cjTF9/
We can hide particular days of week from fullcalendar by Setting hiddenDays property.
i need to hide alternate saturdays of a month.
is it possible in any way ?
You can use the dayRender
callback function:
This callback lets you modify day cells that are part of the month, basicWeek, and basicDay views. See Available Views.
date is the native Date object for the given day.
to check if the displayed is an odd saturday; to do so you can get the number of week of the date and check if it's odd.
Code:
Date.prototype.getWeekOfMonth = function(exact) {
var month = this.getMonth()
, year = this.getFullYear()
, firstWeekday = new Date(year, month, 1).getDay()
, lastDateOfMonth = new Date(year, month + 1, 0).getDate()
, offsetDate = this.getDate() + firstWeekday - 1
, index = 1 // start index at 0 or 1, your choice
, weeksInMonth = index + Math.ceil((lastDateOfMonth + firstWeekday - 7) / 7)
, week = index + Math.floor(offsetDate / 7)
;
if (exact || week < 2 + index) return week;
return week === weeksInMonth ? index + 5 : week;
};
function isOdd(num) { return num % 2;}
$('#mycalendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: [{
title: 'event1',
start: '2014-01-07'
}, {
title: 'event2',
start: '2014-01-10',
end: '2013-05-15'
}, {
title: 'event3',
start: '2014-01-13 12:30:00',
allDay: false // will make the time show
}],
dayRender: function (date, cell) {
if (date.getDay() == 6 && isOdd(date.getWeekOfMonth())) {
$(cell).addClass('fc-disabled');
}
}
});
Demo: http://jsfiddle.net/IrvinDominin/cjTF9/
这篇关于在完整日历中设置自定义隐藏日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!