简体   繁体   English

全日历,如何限制月视图中每天的事件数

[英]fullcalendar, how to limit the number of events per day in the month view

I have many events on a day, and it works as expected but now looking at the month view, my calendar grid is much taller that expected. 我一天有很多事件,它按预期运行,但是现在查看月视图,我的日历网格比预期的高得多。 I'd like to hide some of these events from the month view, like a summary with a visual que that there are more on this day than can be shown. 我想从月视图中隐藏一些此类事件,例如带有可视化提示的摘要,表明这一天的活动量超出了显示的范围。

I can use eventRender and return false, but i would like to know how many events are on a given day, so i can limit the rendering to about 4, then perhaps i would add an event that says " more ... " 我可以使用eventRender并返回false,但是我想知道在给定的一天中有多少个事件,因此我可以将渲染次数限制为4个,那么也许我会添加一个表示“更多...”的事件。

So the question may be : how to count the events on a given date ? 所以问题可能是:如何计算给定日期的事件?

or is this more like a feature request to expose a max counter for month view ? 还是更像一个功能请求,以公开一个最大的月视图计数器?

thanks 谢谢

As of FullCalendar 2.1.0, this feature is included, just use: 从FullCalendar 2.1.0开始,此功能已包括在内,只需使用:

$('#calendarBlock').fullCalendar({
    eventLimit: true
    [...]
});

Demo: http://arshaw.com/js/fullcalendar-2.1.0-beta2/demos/agenda-views.html 演示: http : //arshaw.com/js/fullcalendar-2.1.0-beta2/demos/agenda-views.html

Documentation: http://fullcalendar.io/docs/display/eventLimit/ 文档: http : //fullcalendar.io/docs/display/eventLimit/

currently not possible. 目前不可能。 see feature request: http://code.google.com/p/fullcalendar/issues/detail?id=304 查看功能请求: http : //code.google.com/p/fullcalendar/issues/detail?id=304

I have a similar requirement and was thinking of doing something like this: 我有一个类似的要求,并正在考虑做这样的事情:

in json feed, I would return special events that contain a count of events for each day. 在json feed中,我将返回特殊事件,其中包含每天的事件计数。

Using appropriate full calendar eventRender callback, I would only display these special total count events depending on view by returning false in eventRender() for any events I don't want to see. 使用适当的完整日历eventRender回调,我只会根据视图通过在eventRender()中为我不想看到的任何事件返回false来显示这些特殊的总数事件。

I haven't implemented this yet, but perhaps it can be a valid avenue. 我还没有实现,但是也许它是一个有效的途径。 Correct me if I'm wrong. 如果我错了纠正我。

This buggy (mostly abandoned) plugin does 这个越野车(大部分是废弃的)插件确实 exactly 究竟 what you're asking for. 您要的是什么。 Check it out, and feel free to contribute. 快来看看,并随时贡献自己的力量。 Warning: It is a hack, but fullcalendar itself has an API that needs a lot of work. 警告:这是一个hack,但是fullcalendar本身具有需要大量工作的API。 Most of the important parts are trapped in a closure, which makes it very difficult to extend. 大多数重要部件都被封闭在一个封闭物中,这使其很难扩展。 There really is no way to accomplish this without hackery, unless you want to edit the plugin's source code. 除非您要编辑插件的源代码,否则如果没有黑客,实际上是没有办法实现的。

That being said, this is the closest I have found to what you are asking for: https://github.com/lyconic/fullcalendar/tree/view-more 话虽如此,这是我找到的最接近您要求的内容: https : //github.com/lyconic/fullcalendar/tree/view-more

I am doing like this 我就是这样

Css: CSS:

        .MaxHght
        {
        height:16px;
        }
        .viewMore
        {
        float:right;
        color: rgb(219, 104, 28);
        cursor:pointer;
        }

plugin code 插件代码

dayClick: function (date, allDay, jsEvent, view) {
                   $('#fullCalendar').fullCalendar('changeView', 'agendaDay').fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate());
               },
eventRender: function (event, element, view) {
                element.qtip({
                   content: event.QText,

                   position: {
                       my: 'CenterBottom',
                           at:'TopCenter'

                   },
                   style: {
                       tip: 'bottomMiddle'

                   }
               });
               $(element).removeClass('MaxHght');
               if (view.name == 'month') {

                       $(element).addClass('MaxHght');
                   var year = event.start.getFullYear(), month = event.start.getMonth() + 1, date = event.start.getDate();
                   var result = year + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date);
                   $(element).addClass(result);
                   var ele = $('td[data-date="' + result + '"]'),count=$('.' + result).length;
                   $(ele).find('.viewMore').remove();
                   if ( count> 3) {
                       $('.' + result + ':gt(2)').remove();                          
                       $(ele).find('.fc-day-number').after('<a class="viewMore"> More</a>');

                   } 
               }

           },
           eventAfterAllRender: function (view) {
               if (view.name == 'month') {
                   $('td.fc-day').each(function () {
                       var EventCount = $('.' + $(this).attr('data-date')).length;
                       if (EventCount == 0)
                           $(this).find('.viewMore').remove();
                   });
               }
           },

You don't need to take much effort on taking the total count of events. 您无需花费太多精力就可以统计事件的总数。 I have got a simple way to count total events on my fullCalendar. 我有一种简单的方法来计算我的fullCalendar上的事件总数。 In the eventAfterAllRender , write something like this, eventAfterAllRender ,编写这样的内容,

eventAfterAllRender: function(view) {
                    var allevents = $('#calendar').fullCalendar('clientEvents');
                    var countevents = 0;
                    if( allevents.length ) {
                        countevents = countevents + allevents.length;
                    }
                    if(!countevents) {
                        // alert('event count is'+countevents);
                        console.log('event count is',countevents);
                    }
                }

-where calendar is my calendar # - calendar是我的日历#

This is all my way of doing. 这是我的全部方式。 I am taking left from here. 我从这里离开。 But I am sure, it is not that harder if you try something on the loading: function() of the fullCalendar to limit the number of events according to your wish. 但是我敢肯定,如果您尝试在fullCalendar的loading: function()上进行一些操作以根据您的意愿限制事件的数量,这并不难。

Thanks though. 不过谢谢

I did something like this: 我做了这样的事情:

function(start, end, callback) {
                var viewName = $("#calendar").fullCalendar('getView');
                var startTime = Math.round(start.getTime() / 1000);
                var endTime = Math.round(end.getTime() / 1000);
                MyWebService.MyWebMethod.GetEventsByView(startTime, endTime, viewName.name,
                    function(args) {
                        callback(args);
                    },
                    function(error) {
                        var e = error;
                    }
                );
            }

Here the GetEventsByView method returns a grouped set for month view and detailed set for agendaWeek and day views. 在这里, GetEventsByView方法返回用于月视图的分组集和用于议程周和日视图的详细集。 But for this to work correctly, I had to set lazyFetching:false for the calendar. 但是,要使其正常工作,我必须为日历设置lazyFetching:false

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

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