jQuery FullCalendar event sorting

前端 未结 5 1171
南方客
南方客 2020-12-16 05:24

I have numerous events that are all day events, and all start at the same time. I create the events in the order I would like them to appear on the full calendar view, but t

5条回答
  •  攒了一身酷
    2020-12-16 05:50

    I would like to add something to the RageAgainTheMachine response.

    If you want to completely override the sorting by start date (allDaySlot & month & basics views). For example to sort them by color.

    1.Initialise eventOrder to color.

    eventOrder: 'color,start'

    2.Change the compareSegs function.

    // 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
    

提交回复
热议问题