简体   繁体   English

FullCalendar:如何在MonthView的一天中对事件进行排序和显示?

[英]FullCalendar: How to sort & display Events on Day of MonthView?

All events on day slot of monthly view are sorted based on the start time ie event start hour 0-23, hour 0 on top and 23 on bottom. 每月视图的时段中的所有事件均基于开始时间进行排序,即事件开始时间0-23,小时0在顶部,底部23。

But I want to show the active( event.IsActive == true ) tasks on top and after the Active task list, inactive( event.IsActive == false ) tasks will be displayed sorted by start hour 0-23. 但是我想在活动任务列表的顶部和顶部显示active( event.IsActive == true )任务,非活动( event.IsActive == false )任务将按开始时间0-23显示。

Example: 例:

  1. ActiveTask-1 12:00AM ActiveTask-1 12:00 AM
  2. ActiveTask-2 3:00AM ActiveTask-2 3:00 AM
  3. ActiveTask-3 21:45PM ActiveTask-3 21:45 PM
  4. InactiveTask-1 12:00AM InactiveTask-1 12:00 AM
  5. InactiveTask-2 7:00AM InactiveTask-2 7:00 AM
  6. InactiveTask-3 23:30PM InactiveTask-3 23:30 PM

Is this possible in fullCalendar? 全日历有可能吗?

Your request will need to directly patch the fullcalendar code. 您的请求将需要直接修补完整日历代码。 This is mandatory because fullcalendar doesn't expose this function to the outside world. 这是强制性的,因为fullcalendar不会将此功能公开给外界。

I did check my response with version 1.4.11, but looking at the 1.5 branch on github shows that it should be the same. 我确实用1.4.11版本检查了响应,但查看github上的1.5分支表明它应该是相同的。

The function to be patched is segCmp , (found in src/util.js for the source version, or simply near the end of the file in fullcalendar.js) 要修补的功能是segCmp (在src/util.js找到源版本,或者在fullcalendar.js中仅在文件末尾找到)。

The original version is: 原始版本是:

function segCmp(a, b) {
  return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
}

The patched version should look like that: 修补后的版本应如下所示:

function segCmp(a, b) {
  var activeDiff = ((b.event.IsActive || false) - (a.event.IsActive || false));
  if (activeDiff != 0) return activeDiff;
  return (b.msLength - a.msLength) * 100 + (a.event.start - b.event.start);
}

I simply check wether the events have a different IsActive state and return the diff, if no diff the previous algorithm is preserved. 我只是简单地检查事件是否具有不同的IsActive状态,并返回差异,如果没有差异,则保留先前的算法。 (Note the b - a diff because you want IsActive:true BEFORE IsActive:false) (请注意b-一个差异,因为您想要IsActive:true,然后再选择IsActive:false)

Note that segCmp is called when splitting/ordering events and thus will apply in all views. 请注意,分割/排序事件时会调用segCmp ,因此它将应用于所有视图。

Best Regards, 最好的祝福,

Pascal 帕斯卡

实施此功能后,它将解决您的问题: http : //code.google.com/p/fullcalendar/issues/detail?id=364

If you want to completely override the sorting by start date for allDaySlot, month, basics views. 如果要完全替代allDaySlot,月份,基本视图的开始日期排序。 For example to sort them by color. 例如,按颜色对它们进行排序。

1.Initialise eventOrder to color. 1.初始化eventOrder进行着色。 (html/php file you are using) (您使用的html / php文件)

eventOrder: 'color,start'

2.Change the compareSegs function. 2.更改compareSegs功能。 (fullcalendar.js) (fullcalendar.js)

// original function
compareSegs: function(seg1, seg2) {
    return seg1.eventStartMS - seg2.eventStartMS || // earlier events go first
        seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first
        seg2.event.allDay - seg1.event.allDay || // tie? put all-day events first (booleans cast to 0/1)
        compareByFieldSpecs(seg1.event, seg2.event, this.view.eventOrderSpecs);
}

// custom function
compareSegs: function(seg1, seg2) {
    if(this.view.name=="basicWeek"){ // ordering events by color in ListView
    return seg2.event.allDay - seg1.event.allDay || // tie? put all-day events first (booleans cast to 0/1)
        compareByFieldSpecs(seg1.event, seg2.event, this.view.eventOrderSpecs);
    }
    else{
        return seg1.eventStartMS - seg2.eventStartMS || // earlier events go first
                    seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first
                    seg2.event.allDay - seg1.event.allDay || // tie? put all-day events first (booleans cast to 0/1)
                    compareByFieldSpecs(seg1.event, seg2.event, this.view.eventOrderSpecs);
    }
}

In this case I only want to sort event by color in the "basicVeek" view. 在这种情况下,我只想在“ basicVeek”视图中按颜色对事件进行排序。 Then I have remove the eventStartMS & eventDurationMS tests. 然后,我删除了eventStartMS和eventDurationMS测试。

REMOVE: 去掉:

seg1.eventStartMS - seg2.eventStartMS || // earlier events go first
seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first

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

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