javascript - FullCalendar 资源 View - 显示前 3 天的周 View

标签 javascript jquery fullcalendar fullcalendar-scheduler fullcalendar-4

我在下面提供了一个 TimelineResourceView 作为当前设置示例的引用。

示例:如果周 View 周日至周六,则无论何时向前/向后导航,始终显示周 View 以及周范围内的前 3 天。然后,无论何时向前/向后导航,始终显示周范围内前 3 天的周 View 。

FullCalendar 时间线示例 ResourceWeekView https://codepen.io/motogeek/pen/yLLpjLV

我尝试了文档中的许多不同内容,例如“visiblerange”和强制日期,但没有成功。

https://fullcalendar.io/docs/visibleRange

[10 月 27 日星期日 - 11 月 2 日星期六],但他们希望查看 [10 月 24 日星期四 - 11 月 2 日星期六] 以显示前 3 天。

calendar.setOption('visibleRange', {
  start: '2019-10-24',
  end: '2019-11-02'
});

最佳答案

坚持得到了返回。我使用 VisibleRange 和 Moment javascript 库实现了自定义 View 。我自己回答这个问题,知道这可能对其他人制定自定义 View 有所帮助。我的重点是时间线资源 View ,但应该能够应用于其他日/周 View 等。

参见CodePen: Working Example Week View with Previewing Last 3 days (10 Day View)

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');

  var calendar = new FullCalendar.Calendar(calendarEl, {
    plugins: [ 'interaction', 'resourceTimeline' ],
    timeZone: 'UTC',
    header: {
      left: 'today',
      center: 'title',
      right: 'resourceTimeline'
    },        
    defaultView: 'resourceTimeline',
                    views: {
                        resourceTimeline: {
                            visibleRange: function (currentDate) {
                                // Generate a new date for manipulating in the next step
                                var startDate = new Date(moment(currentDate).startOf('week').format("YYYY-MM-DD"));
                                var endDate = new Date(moment(currentDate).startOf('week').format("YYYY-MM-DD"));

                                // Adjust the start & end dates, respectively

                                //10 Day WeekView PREV Thurs -> Sun-Sat
                                startDate.setDate(startDate.getDate() - 3); //Set Past (show back Thur)
                                endDate.setDate(endDate.getDate() + 7); // Set Future (standard week from Sun)
                                return { start: startDate, end: endDate };
                            }
                        }
                    },
     slotLabelFormat: [{ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }],
                slotLabelInterval: { days: 1 },
    editable: true,
    resourceLabelText: 'Rooms',
    resources: 'https://fullcalendar.io/demo-resources.json?with-nesting&with-colors',
    events: 'https://fullcalendar.io/demo-events.json?single-day&for-resource-timeline'
  });

  calendar.render();

  document.getElementById('prev').addEventListener('click', function() {
    calendar.incrementDate({ days: -7 });  
  });

  document.getElementById('next').addEventListener('click', function() {
    calendar.incrementDate({ days: 7 });  
  });

});

关于javascript - FullCalendar 资源 View - 显示前 3 天的周 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58701128/

相关文章:

javascript - jQuery 的 val() 方法为按键事件返回的字符太少

javascript - IE 6 JQuery 切换类错误!帮助!

angular - fullcalendar v4 外部放置事件

javascript - Node JS中事件代码的同步执行

javascript - 提交表单后如何将注意力集中在叠加弹出窗口上?

JavaScript new Date(string) 兼容大多数浏览器(2016 年 12 月)

javascript - Bootstrap 3 Modal 不会显示模态标题或输入标签

javascript - jQuery FullCalendar- 丢弃事件的默认结束时间

javascript - "Uncaught TypeError: Cannot read property ' 将重复事件添加到数据库时克隆 ' of undefined"

java - 如何在jsp页面中访问javascript变量