按开始日期和结束日期订购Fullcalendar中的事件

时间:2017-09-05 10:15:36

标签: fullcalendar

如何在开始日期之前首先在fullCalendar中订购事件?

示例:

  • 首先开始的事件将显示在顶部,然后稍后开始的事件将显示在
  • 如果两个事件的开始日期相同,请按结束日期排序 即 将首先显示先前结束的事件,然后显示稍后结束的事件。

Calendar Display Events Order

var args = jQuery.parseJSON(emCalendarArgs);
var Jobj = args.events;

// Setup FullCalendar

(function() {
  //var language = jQuery('#pg_lang').val();
  //alert(language+ 'dsfsd');
  var date = new Date();
  var d = date.getDate();
  var m = date.getMonth();
  var y = date.getFullYear();
  var language = langg;
  var mn_text, week_text, day_text, list_text;

  //alert(mn_text);
  var args = jQuery.parseJSON(emCalendarArgs);
  var Jobj = args.events;
  console.log(Jobj);
  jQuery('#events-full-calendar').fullCalendar({

    allDaySlot: false,
    editable: true,
    lang: 'he',
    handleWindowResize: true,
    eventOrder: 'start,end',
    header: {
      left: 'today prev,next',
      center: 'title',
      right: 'month,basicWeek,basicDay'
    },
    buttonText: {
      month: mn_text,
      week: week_text,
      day: day_text
    },
    eventLimit: {
      'month': 3, // adjust to 4 only for months
      'default': false // display all events for other views
    },
    axisFormat: 'HH:mm',
    timeFormat: {
      agenda: 'H:mm{ - h:mm}'
    },
    slotEventOverlap: false,
    events: Jobj,
    timeFormat: 'H:mm',
  });
}());

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。对于寻找解决方案的任何其他人,我在fullcalendar.js中更改了一个函数:

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); } 

到:

compareSegs: function(seg1, seg2) {
        if(this.view.name=="basicWeek" || this.view.name=="month" || this.view.name=="basicDay"){ // 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);
        }
    }

并在fullcalendar函数中使用下面的代码

eventOrder: 'start, end' 

在我的fullcalendar电话中