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

半世苍凉 提交于 2019-11-29 16:30:50

Your request will need to directly patch the fullcalendar code. This is mandatory because fullcalendar doesn't expose this function to the outside world.

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.

The function to be patched is segCmp, (found in src/util.jsfor the source version, or simply near the end of the file in 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. (Note the b - a diff because you want IsActive:true BEFORE IsActive:false)

Note that segCmp is called when splitting/ordering events and thus will apply in all views.

Best Regards,

Pascal

when this feature is implemented, it would solve your problem: 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. For example to sort them by color.

1.Initialise eventOrder to color. (html/php file you are using)

eventOrder: 'color,start'

2.Change the compareSegs function. (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. Then I have remove the eventStartMS & eventDurationMS tests.

REMOVE:

seg1.eventStartMS - seg2.eventStartMS || // earlier events go first
seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!