简体   繁体   English

在上班时间上加快fullcalendar.io

[英]Speeding up fullcalendar.io on shift roster

I have a shift roster generated using fullcalendar.io. 我有一个使用fullcalendar.io生成的班次名册。

I'm following and expanding on this tutorial: How can I create an event based on pattern for calendar? 我正在关注并扩展本教程: 如何基于日历模式创建事件?

I have events spanned over a time period of 50 years. 我的活动跨越了50年。

This makes the whole calendar laggy and heavy rather than lightweight. 这使整个日历变得漫长而沉重,而不是轻巧。 Prev/Next buttons are slow. 上一个/下一个按钮很慢。 Especially, for dayClick callback when the dates are filtered over all of the events created weekly over a period of 50 years, it takes a couple of seconds for the event to get executed. 特别是对于dayClick回调,当在50年的时间内每周对所有创建的事件进行日期过滤时,事件需要花费几秒钟的时间才能执行。

I think its the logic behind the creation. 我认为这是创作背后的逻辑。 When I lessen the period to generate the events, the whole process gets faster. 当我缩短生成事件的时间时,整个过程会变得更快。

here is for the full illustration: https://codepen.io/gunblaze/pen/OZKBvE . 这是完整的插图: https : //codepen.io/gunblaze/pen/OZKBvE

the day click is still the slowest due to its filtering, i guess: 由于其过滤功能,一天点击仍然是最慢的,我想:

..
dayClick: function(date, allDay, jsEvent, view) {
            $('#calendar').fullCalendar('clientEvents', function(event) {
                // match the event date with clicked date if true render clicked date events
                if(event.rendering == 'background'){
                    if (moment(date).format('YYYY-MM-DD') == event.start.format('YYYY-MM-DD')) {
            // do your stuff here
            $("#instructions").html(moment(date).format('YYYY-MM-DD')+': on ' +event.title+' shift.') 
                    }                   
                }
            });
}
..

You're front-loading all your data; 您正在预先加载所有数据; with 50 years of data, no way to prevent that from being slow. 拥有50年的数据,没有办法阻止它变慢。

If you have a server component you might want to think about serving up the data in smaller chunks. 如果您有服务器组件,则可能需要考虑以较小的块来提供数据。 The documentation describes how to do this, but here's a quick sketch: 文档描述了如何执行此操作,但是这里有一个简单的草图:

$('#calendar').fullCalendar({
  events: '/myfeed.php'
});

This would result in your server receiving a query string like this: 这将导致您的服务器收到如下查询字符串:

/myfeed.php?start=2013-12-01&end=2014-01-12&_=1386054751381

Then you can filter your calendar data on the server side to only return the data between start and end . 然后,您可以在服务器端过滤日历数据,仅返回startend之间的数据。 This will generally be much more efficient if you can do it as part of your SQL query (assuming you're using a SQL database) as opposed to trying to filter in a javascript array. 如果您可以将其作为SQL查询的一部分(假设您使用的是SQL数据库)来进行操作,而不是尝试在javascript数组中进行过滤,那么这样做通常会更加高效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM