【问题标题】:Fullcalendar using week view, navigate month by month instead of week by weekFullcalendar 使用周视图,按月而不是按周导航
【发布时间】:2017-08-13 21:13:42
【问题描述】:

我正在使用 fullcalendar 为一所学校实施时间表,其中课程在整个月的特定日期进行,例如课程可以在 TTH 或 MWF、TWTH

我正在尝试实现周视图,但我想逐月导航,因此我不必在整个月的每个特定日期都显示相同的课程(月视图)。受this question 的启发,我尝试实现以下内容:

$('#calendar').fullCalendar({
defaultView: 'customWeek',
views: {
    customWeek: {
        type: 'week',
        duration: {months: 1}
    }
}
});

但是这个实现并没有强制视图在月初开始,所以如果我浏览日历,下一个视图将在每月的第二天或第三天,或者有时在最后一天开始上个月。

我还尝试使它在月视图上与 CSS 一起使用,使其看起来像周视图:

.fc-day-top .fc-day-number{
   display: none;
}

.fc td {
  border-bottom: 0 !important;
  border-top: 0 !important;
}

.fc-head {
  border-top: 1px solid black !important;
  border-bottom: 1px solid black !important;
}
.fc-body{
  border-bottom: 1px solid black !important;
}

但我丢失了日历开头的时间段,事件卡在了顶部,看起来很糟糕。

所以我正在寻找完成这项任务的最佳方法。

【问题讨论】:

  • 您的问题到底是什么?您需要像 now() 这样的默认日期吗?
  • 我想在周视图中显示特定月份的课程,并允许用户逐月导航(而不是逐周)
  • 你的意思是周视图的用户和月视图的用户不同?我的意思是当用户登录到您的系统时。或者它只是用户的一个角色。
  • 一个用户角色? i want to show the classes taken for a specific month in a week view, and allow the user to navigate month by month( not week by week)
  • @LouysPatriceBessette 如果我能展示第一个完整的一周,那就太好了。谢谢你的时间:)

标签: jquery angularjs fullcalendar


【解决方案1】:

那个很有趣!所以诀窍是隐藏我们不想在月视图中看到的.fc-week 行。这样,我们就不必乱用正常的导航了。

为此,我们必须定位我们想要查看的行。我在这里做了两个选择:

  1. 包含该月 1 日的那一周
  2. 第一个完整的一周(没有上个月的一天)

它可以使用两个布尔值在代码中“切换”。现在设置为第二个选项。

请随时提出任何问题! ;)

// Switches about what to display
// Use only one of the two to true.
var FIND_first_full_week = true;
var FIND_first_day_of_month = false;


$("#calendar").fullCalendar({

  viewRender: function(){
    var ShowWeek;
    var weeks = $(".fc-week");

    // Find the first day of the month
    if(FIND_first_day_of_month){
      for(i=0;i<weeks.length;i++){
        var days = weeks.eq(i).find(".fc-day-number");
        days.each(function(){
          if( $(this).html()=="1" && !$(this).parent().is(".fc-other-month") ){
            ShowWeek = i;
          }
        });
      }
    }
    
    // Find first full week of the month (no day in past month)
    if(FIND_first_full_week){
      for(i=0;i<weeks.length;i++){
        var firstFullWeek = false;
        var dayCount=0;

        var days = weeks.eq(i).find(".fc-day-number");
        days.each(function(){
          if(!firstFullWeek){
            if( !$(this).parent().is(".fc-other-month") ){
              dayCount++;
              if(dayCount==7){
                firstFullWeek = true;
                ShowWeek = i;
                i = weeks.length;
              }
            }
          }
        });
      }
    }
    
    // Fix FullCalendar display!
    setTimeout(function(){
      weeks.not(weeks.eq(ShowWeek)).css({"display":"none"});
      var weekHeight = weeks.height();
      $(".fc-day-grid-container").css({"height":weekHeight});
    },10);
  }
});
/* Your CSS */
.fc td {
  border-bottom: 0 !important;
  border-top: 0 !important;
}

.fc-head {
  border-top: 1px solid black !important;
  border-bottom: 1px solid black !important;
}
.fc-body{
  border-bottom: 1px solid black !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.js"></script>

<div id="calendar"></div>

【讨论】:

  • 我的朋友,我真的很感谢你花时间帮助我,你做了我想要的,我向你致敬,非常感谢
  • 也不知道......但你把它找回来了;)在我看来,你的问题很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-10
  • 1970-01-01
  • 2018-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多