首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FullCalendar资源视图-显示前3天的周视图

问FullCalendar资源视图-显示前3天的周视图
EN

Stack Overflow用户
提问于 2019-11-05 05:11:56
回答 1查看 1.1K关注 0票数 0

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

示例:如果周视图为Sun-Sat,则随时向前/向后导航,始终显示从周范围前3天开始的周视图。然后,任何时候向前/向后导航时,始终显示从周范围的前3天的周视图。

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

我从文档中尝试了许多不同的东西,比如"visiblerange“和强制日期,但都没有成功。

https://fullcalendar.io/docs/visibleRange

周日10月27日-周六11月2日,但他们希望看到10月24日周四-11月2日周六,以显示之前的3天。

代码语言:javascript
复制
calendar.setOption('visibleRange', {
  start: '2019-10-24',
  end: '2019-11-02'
});
EN

回答 1

Stack Overflow用户

发布于 2019-11-06 07:03:30

坚持不懈是有回报的。我使用VisibleRange和Moment javascript库实现了一个自定义视图。我自己回答了这个问题,因为我知道这可能会对其他人形成自定义视图有所帮助。我的重点是timelineResourceViewm,但应该能够应用于其他天/周的视图等。

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

代码语言:javascript
复制
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 });  
  });

});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58701128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档